Created
March 4, 2018 06:49
-
-
Save nirui/3b9194099db5f99721bffbe3159d7424 to your computer and use it in GitHub Desktop.
This file contains 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
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