feat(wpcarro/rust): Define Rc<T> example
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>
This commit is contained in:
		
							parent
							
								
									e23a556873
								
							
						
					
					
						commit
						db9cb70d5d
					
				
					 3 changed files with 15 additions and 2 deletions
				
			
		
							
								
								
									
										12
									
								
								users/wpcarro/scratch/rust/src/rc/mod.rs
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								users/wpcarro/scratch/rust/src/rc/mod.rs
									
										
									
									
									
										Normal file
									
								
							|  | @ -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) | ||||
| } | ||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue