mirror of
https://github.com/ahgamut/rust-ape-example.git
synced 2024-05-14 17:42:41 +00:00
28 lines
400 B
Rust
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();
|
|
}
|
|
|