Cow (clone-on-write)
Në shqip përdoret i njëjti emër.
ShpjegimiSQ
Cow<str> mund të jetë ose një referencë (pa kopjim) ose një String i ri — kopjon vetëm kur duhet ta ndryshojë. Optimizim i zakonshëm kur shumicën e herëve teksti mbetet i njëjtë.
EnglishEN
Cow<str> can be either a reference (no copy) or a new String — it copies only when it has to modify. A common optimisation when the text usually stays the same.
Si ta mendosh
Si ta fotokopjosh një dokument vetëm kur duhet të shkruash mbi të.
Lexoje në anglisht
Like photocopying a document only when you need to write on it.
Shembull kodirust
fn pastro(s: &str) -> Cow<str> {
if s.contains(' ') { Cow::Owned(s.replace(' ', "_")) } else { Cow::Borrowed(s) }
}