doc.rust-lang.org/std/ptr/fn.write.html
Preview meta tags from the doc.rust-lang.org website.
Linked Hostnames
1General Meta Tags
6- titlewrite in std::ptr - Rust
- charsetutf-8
- viewportwidth=device-width, initial-scale=1.0
- generatorrustdoc
- descriptionOverwrites a memory location with the given value without reading or dropping the old value.
Link Tags
4- alternate icon../../static.files/favicon-32x32-6580c154.png
- icon../../static.files/favicon-044be391.svg
- stylesheet../../static.files/normalize-9960930a.css
- stylesheet../../static.files/rustdoc-84e720fa.css
Links
2- https://play.rust-lang.org/?code=%23!%5Ballow(unused)%5D%0Afn+main()+%7B%0A++++let+mut+x+=+0;%0A++++let+y+=+%26mut+x+as+*mut+i32;%0A++++let+z+=+12;%0A++++%0A++++unsafe+%7B%0A++++++++std::ptr::write(y,+z);%0A++++++++assert_eq!(std::ptr::read(y),+12);%0A++++%7D%0A%7D&edition=2024
- https://play.rust-lang.org/?code=%23!%5Ballow(unused)%5D%0Afn+main()+%7B%0A++++use+std::ptr;%0A++++%0A++++fn+swap%3CT%3E(a:+%26mut+T,+b:+%26mut+T)+%7B%0A++++++++unsafe+%7B%0A++++++++++++//+Create+a+bitwise+copy+of+the+value+at+%60a%60+in+%60tmp%60.%0A++++++++++++let+tmp+=+ptr::read(a);%0A++++%0A++++++++++++//+Exiting+at+this+point+(either+by+explicitly+returning+or+by%0A++++++++++++//+calling+a+function+which+panics)+would+cause+the+value+in+%60tmp%60+to%0A++++++++++++//+be+dropped+while+the+same+value+is+still+referenced+by+%60a%60.+This%0A++++++++++++//+could+trigger+undefined+behavior+if+%60T%60+is+not+%60Copy%60.%0A++++%0A++++++++++++//+Create+a+bitwise+copy+of+the+value+at+%60b%60+in+%60a%60.%0A++++++++++++//+This+is+safe+because+mutable+references+cannot+alias.%0A++++++++++++ptr::copy_nonoverlapping(b,+a,+1);%0A++++%0A++++++++++++//+As+above,+exiting+here+could+trigger+undefined+behavior+because%0A++++++++++++//+the+same+value+is+referenced+by+%60a%60+and+%60b%60.%0A++++%0A++++++++++++//+Move+%60tmp%60+into+%60b%60.%0A++++++++++++ptr::write(b,+tmp);%0A++++%0A++++++++++++//+%60tmp%60+has+been+moved+(%60write%60+takes+ownership+of+its+second+argument),%0A++++++++++++//+so+nothing+is+dropped+implicitly+here.%0A++++++++%7D%0A++++%7D%0A++++%0A++++let+mut+foo+=+%22foo%22.to_owned();%0A++++let+mut+bar+=+%22bar%22.to_owned();%0A++++%0A++++swap(%26mut+foo,+%26mut+bar);%0A++++%0A++++assert_eq!(foo,+%22bar%22);%0A++++assert_eq!(bar,+%22foo%22);%0A%7D&edition=2024