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

24 lines
437 B
Rust
Raw Permalink Normal View History

// ./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:
2022-09-07 05:36:14 +00:00
// print_it(&i);
}
pub fn main() {
part0();
}