Skip to content

Instantly share code, notes, and snippets.

@halhenke
Forked from rust-play/playground.rs
Created October 21, 2018 14:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save halhenke/d5adb6383a39668153e89aee2ae1515a to your computer and use it in GitHub Desktop.
Save halhenke/d5adb6383a39668153e89aee2ae1515a to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
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