Skip to content

Question about takeaway from drop_static<T: 'static>(t: T) #48

Answered by WaffleLapkin
maxim-ge asked this question in Q&A
Discussion options

You must be logged in to vote
fn print_static<T: 'static + std::fmt::Display>(t: T) {
    println!("{}", t);
}

fn main(){
    let s = String::from("Hello");
    print_static(&s); // `&s` can't live till the end of the program, since `s` is dropped
}

[playground]

Replies: 1 comment 5 replies

Comment options

You must be logged in to vote
5 replies
@maxim-ge
Comment options

@pretzelhammer
Comment options

@maxim-ge
Comment options

@WaffleLapkin
Comment options

Answer selected by pretzelhammer
@maxim-ge
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants