// dictionary
借用(Borrowing).
借用(Borrowing)
借用は、所有権(Ownership)を譲渡することなく値にアクセスする方法です。Rustでは不変借用と可変借用の2種類があります。
不変借用(Immutable Reference)
fn main() {
let s = String::from("hello");
let len = calculate_length(&s);
println!("'{}' の長さは {}", s, len);
}
fn calculate_length(s: &String) -> usize {
s.len()
}
可変借用(Mutable Reference)
fn main() {
let mut s = String::from("hello");
change_string(&mut s);
println!("{}", s);
}
fn change_string(s: &mut String) {
s.push_str(" world");
}
詳細はライフタイム(Lifetime)を参照してください。
この辞書が使われているページ
backlinks 5