Skip to content

How do you use HttpRequest data? #1824

Answered by fakeshadow
ttfkam asked this question in Q&A
Discussion options

You must be logged in to vote

This is how lifetime works in Rust.

Your some_header is referencing the HttpRequest which is owned by your print_header function.
When the function is end HttpRequest is dropped and it's memory is not valid anymore.

If you are still confused with how Rust's borrow checker work it best to start with The book

For this specific case, some_header is a &str and it needs to be a String to return it. So use .to_owned().

Replies: 3 comments 3 replies

Comment options

You must be logged in to vote
2 replies
@ttfkam
Comment options

@ttfkam
Comment options

Answer selected by robjtede
Comment options

You must be logged in to vote
1 reply
@ttfkam
Comment options

Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants