Created
October 21, 2018 14:29
-
-
Save rust-play/b14e654041f5c4a858dd4b37acdec4f8 to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::rc::Rc; | |
extern crate core; | |
use core::cell::RefCell; | |
use std::ops::Deref; | |
type RT = Rc<RefCell<Thing>>; | |
struct Thing { | |
a: Vec<String>, | |
} | |
struct ThingThree { | |
a: Rc<RefCell<Thing>>, | |
} | |
impl ThingThree { | |
fn new(aa: RT) -> Self { | |
ThingThree { | |
a: aa, | |
} | |
} | |
} | |
// fn self_ref() -> FnOnce(i32) -> i32 { | |
fn self_ref() -> Box<FnOnce(i32) -> i32> { | |
// let t1 = Thing { | |
// a: vec!(String::from("abba")), | |
// }; | |
// let tt = Rc::new(RefCell::new(t1)); | |
let tt = Rc::new(RefCell::new( | |
Thing { | |
a: vec!(String::from("abba")), | |
} | |
)); | |
let ttt = Rc::new(ThingThree::new(tt)); | |
// let ttt2 = Rc::new(ttt); | |
// let tt2 = Rc::new(tt); | |
// let tt3 = tt2.clone(); | |
// let t4 = ThingThree::new(tt3.borrow().deref()); | |
// let t4 = ThingThree::new(tt2, String::from("ts2")); | |
// println!("{}", &t1.b); | |
// println!("{}", t2.b); | |
// println!("{}", t3.b); | |
return Box::new(move |x| { | |
ttt; | |
// t3; | |
// t4; | |
x + 2 | |
}); | |
} | |
fn main() { | |
let x: i32 = 5; | |
let z: &i32 = &x; | |
let a = z; | |
let e = *z; | |
self_ref(); | |
println!("z: {}", z); | |
println!("a: {}", a); | |
println!("e: {}", e); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment