move closures
Në shqip: Closure-t me move
ShpjegimiSQ
Me move ||, closure merr në pronësi variablat që përdor, në vend që t'i huazojë. E domosdoshme kur closure jeton më gjatë se funksioni — p.sh. në thread::spawn.
EnglishEN
With move ||, the closure takes ownership of the variables it uses instead of borrowing them. Essential when the closure outlives the function — e.g. in thread::spawn.
Si ta mendosh
Si t'i marrësh sendet me vete kur shpërngulesh, në vend që t'i lësh te fqinji.
Lexoje në anglisht
Like taking your things with you when you move instead of leaving them with a neighbour.
Shembull kodirust
let emri = String::from("Arta");
let h = std::thread::spawn(move || println!("Tung, {emri}"));
h.join().unwrap();