Une collection organisée de snippets de code pour accélérer votre développement. Parcourez, recherchez et copiez en un clic.
let s1 = String::from("hello");
let s2 = s1.clone();
println!("s1 = {}, s2 = {}", s1, s2);
fn prend_possession(une_string: String) { ... }
let s = String::from("hello");
prend_possession(s); // s n'est plus valide ici
fn donne_possession() -> String {
let une_string = String::from("la vôtre");
une_string
}
fn calcule_longueur(s: &String) -> usize {
s.len()
}
let s1 = String::from("hello");
let len = calcule_longueur(&s1);
fn change(une_string: &mut String) {
une_string.push_str(", world");
}
let mut s = String::from("hello");
change(&mut s);
let s1 = String::from("hello");
let s2 = s1;
// println!("{}", s1); // Erreur de compilation ! s1 a été déplacé vers s2.
let s = String::from("hello world");
let hello = &s[0..5];
let world = &s[6..11];