doc.rust-lang.org/nightly/std/rc
Preview meta tags from the doc.rust-lang.org website.
Linked Hostnames
2General Meta Tags
6- titlestd::rc - Rust
- charsetutf-8
- viewportwidth=device-width, initial-scale=1.0
- generatorrustdoc
- descriptionSingle-threaded reference-counting pointers. ‘Rc’ stands for ‘Reference Counted’.
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-069232aa.css
Links
6- https://doc.rust-lang.org/book/ch19-03-advanced-traits.html#fully-qualified-syntax-for-disambiguation-calling-methods-with-the-same-name
- https://play.rust-lang.org/?code=%23!%5Ballow(unused)%5D%0Afn+main()+%7B%0A++++use+std::rc::Rc;%0A++++%0A++++let+foo+=+Rc::new(vec!%5B1.0,+2.0,+3.0%5D);%0A++++//+The+two+syntaxes+below+are+equivalent.%0A++++let+a+=+foo.clone();%0A++++let+b+=+Rc::clone(%26foo);%0A%7D&edition=2024
- https://play.rust-lang.org/?code=%23!%5Ballow(unused)%5D%0Afn+main()+%7B%0A++++use+std::rc::Rc;%0A++++%0A++++let+my_rc+=+Rc::new(());%0A++++let+my_weak+=+Rc::downgrade(%26my_rc);%0A%7D&edition=2024
- https://play.rust-lang.org/?code=%23!%5Ballow(unused)%5D%0Afn+main()+%7B%0A++++use+std::rc::Rc;%0A++++%0A++++let+rc+=+Rc::new(());%0A++++//+Method-call+syntax%0A++++let+rc2+=+rc.clone();%0A++++//+Fully+qualified+syntax%0A++++let+rc3+=+Rc::clone(%26rc);%0A%7D&edition=2024
- https://play.rust-lang.org/?code=%23!%5Ballow(unused)%5D%0Ause+std::rc::Rc;%0A%0Astruct+Owner+%7B%0A++++name:+String,%0A++++//+...other+fields%0A%7D%0A%0Astruct+Gadget+%7B%0A++++id:+i32,%0A++++owner:+Rc%3COwner%3E,%0A++++//+...other+fields%0A%7D%0A%0Afn+main()+%7B%0A++++//+Create+a+reference-counted+%60Owner%60.%0A++++let+gadget_owner:+Rc%3COwner%3E+=+Rc::new(%0A++++++++Owner+%7B%0A++++++++++++name:+%22Gadget+Man%22.to_string(),%0A++++++++%7D%0A++++);%0A%0A++++//+Create+%60Gadget%60s+belonging+to+%60gadget_owner%60.+Cloning+the+%60Rc%3COwner%3E%60%0A++++//+gives+us+a+new+pointer+to+the+same+%60Owner%60+allocation,+incrementing%0A++++//+the+reference+count+in+the+process.%0A++++let+gadget1+=+Gadget+%7B%0A++++++++id:+1,%0A++++++++owner:+Rc::clone(%26gadget_owner),%0A++++%7D;%0A++++let+gadget2+=+Gadget+%7B%0A++++++++id:+2,%0A++++++++owner:+Rc::clone(%26gadget_owner),%0A++++%7D;%0A%0A++++//+Dispose+of+our+local+variable+%60gadget_owner%60.%0A++++drop(gadget_owner);%0A%0A++++//+Despite+dropping+%60gadget_owner%60,+we're+still+able+to+print+out+the+name%0A++++//+of+the+%60Owner%60+of+the+%60Gadget%60s.+This+is+because+we've+only+dropped+a%0A++++//+single+%60Rc%3COwner%3E%60,+not+the+%60Owner%60+it+points+to.+As+long+as+there+are%0A++++//+other+%60Rc%3COwner%3E%60+pointing+at+the+same+%60Owner%60+allocation,+it+will+remain%0A++++//+live.+The+field+projection+%60gadget1.owner.name%60+works+because%0A++++//+%60Rc%3COwner%3E%60+automatically+dereferences+to+%60Owner%60.%0A++++println!(%22Gadget+%7B%7D+owned+by+%7B%7D%22,+gadget1.id,+gadget1.owner.name);%0A++++println!(%22Gadget+%7B%7D+owned+by+%7B%7D%22,+gadget2.id,+gadget2.owner.name);%0A%0A++++//+At+the+end+of+the+function,+%60gadget1%60+and+%60gadget2%60+are+destroyed,+and%0A++++//+with+them+the+last+counted+references+to+our+%60Owner%60.+Gadget+Man+now%0A++++//+gets+destroyed+as+well.%0A%7D&edition=2024