Progrust Library.

// 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

  1. 辞書ライフタイム(Lifetime)
  2. 辞書可変性(Mutability)
  3. 辞書所有権(Ownership)
  4. 記事Markdown記法パイプライン検証(全記法)
  5. 記事Rust の所有権を深掘り - メモリ安全性の秘密