diff options
author | William Carroll <wpcarro@gmail.com> | 2022-09-01T16·53-0700 |
---|---|---|
committer | clbot <clbot@tvl.fyi> | 2022-09-06T18·09+0000 |
commit | db9cb70d5d7807adff255e21a04d78c5700d1260 (patch) | |
tree | 722ba88d423735841fe0c4d9358310ee7c6164ea /users/wpcarro/scratch/rust/src/rc/mod.rs | |
parent | e23a55687374d81bb55380081f137873222437f4 (diff) |
feat(wpcarro/rust): Define Rc<T> example r/4687
My foray into "smart pointer" land. Change-Id: I4ca775c72168dd34d90bf88fa41149867cd7fdae Reviewed-on: https://cl.tvl.fyi/c/depot/+/6244 Tested-by: BuildkiteCI Reviewed-by: wpcarro <wpcarro@gmail.com> Autosubmit: wpcarro <wpcarro@gmail.com>
Diffstat (limited to 'users/wpcarro/scratch/rust/src/rc/mod.rs')
-rw-r--r-- | users/wpcarro/scratch/rust/src/rc/mod.rs | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/users/wpcarro/scratch/rust/src/rc/mod.rs b/users/wpcarro/scratch/rust/src/rc/mod.rs new file mode 100644 index 000000000000..67251ca6aa9b --- /dev/null +++ b/users/wpcarro/scratch/rust/src/rc/mod.rs @@ -0,0 +1,12 @@ +// Playing around with Rust's "smart pointers". Starting off with a wrapper type +// that allows multiple readers (owners?) of some data. + +use std::rc::Rc; + +pub fn example() { + let five = Rc::new(5); + let x = Rc::clone(&five); + let y = Rc::clone(&five); + let z = Rc::clone(&five); + println!("result: {}", *x + *y + *z) +} |