rust-ape-example/src/bin/scope_lifetime_static_lifetime.rs
2022-09-07 11:36:05 +05:30

23 lines
437 B
Rust

// ./src/scope/lifetime/static_lifetime.md
use std::fmt::Debug;
fn print_it( input: impl Debug + 'static ) {
println!( "'static value passed in is: {:?}", input );
}
fn part0() {
// i is owned and contains no references, thus it's 'static:
let i = 5;
print_it(i);
// oops, &i only has the lifetime defined by the scope of
// part0(), so it's not 'static:
// print_it(&i);
}
pub fn main() {
part0();
}