Skip to content

Instantly share code, notes, and snippets.

@nirui
Created March 4, 2018 06:49
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 nirui/3b9194099db5f99721bffbe3159d7424 to your computer and use it in GitHub Desktop.
Save nirui/3b9194099db5f99721bffbe3159d7424 to your computer and use it in GitHub Desktop.
struct Test {
n: usize,
}
struct Test2<'a> {
n_borrow: &'a usize,
}
impl Test {
pub fn return_n(&self) -> Test2 {
Test2::new(&self.n)
}
}
impl<'a> Test2<'a> {
pub fn new(n_ref: &usize) -> Test2 {
Test2 {
n_borrow: n_ref,
}
}
pub fn return_n(&self) -> &usize {
self.n_borrow
}
}
fn main() {
let t = Test{n: 10};
println!("Print {:?}", t.return_n().return_n());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment