-
-
Save rust-play/215203903b9b97f6780cd8d614b9faca 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
struct Foo(u32); | |
struct Bar<'c>(&'c Foo); | |
impl<'h, 'c: 'h> Bar<'c> { | |
fn new(foo: &'c mut Foo) -> Bar<'c> { | |
Bar(foo) | |
} | |
fn baz(&'h self) -> Baz<'c> { | |
Baz(&(self.0).0) | |
} | |
} | |
struct Baz<'c>(&'c u32); | |
struct Quix<'c>(Bar<'c>, Option<Baz<'c>>); | |
impl Quix<'_> { | |
fn setup(&mut self) { | |
self.1 = Some(self.0.baz()) | |
} | |
fn mu(&mut self) -> Result<(), Option<u32>> { | |
Err(self.1.as_ref().map(|s| *s.0)) | |
} | |
} | |
fn main() { | |
let c = || { | |
let mut foo = Foo(42); | |
let bar = Bar::new(&mut foo); | |
let mut quix = Quix(bar, None); | |
quix.setup(); | |
quix.mu() | |
}; | |
println!("{:?}", c()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment