rust-book/advanced_lifetimes/src/main.rs

20 lines
297 B
Rust

trait Red {}
struct Ball<'a> {
diameter: &'a i32,
}
impl<'a> Red for Ball<'a> {}
struct StrWrap<'a>(&'a str);
fn foo(string: &str) -> StrWrap<'_> { // Anonymous lifetime
StrWrap(string)
}
fn main() {
let num = 5;
let obj = Box::new(Ball { diameter: &num}) as Box<dyn Red>;
}