rust-ape-example/src/bin/scope_lifetime_trait.rs
2022-09-07 10:49:49 +05:30

28 lines
400 B
Rust

// ./src/scope/lifetime/trait.md
// A struct with annotation of lifetimes.
#[derive(Debug)]
struct Borrowed<'a> {
x: &'a i32,
}
// Annotate lifetimes to impl.
impl<'a> Default for Borrowed<'a> {
fn default() -> Self {
Self {
x: &10,
}
}
}
fn part0() {
let b: Borrowed = Default::default();
println!("b is {:?}", b);
}
pub fn main() {
part0();
}