rust-ape-example/src/bin/scope_lifetime_trait.rs

28 lines
400 B
Rust
Raw Permalink Normal View History

// ./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();
}