Given the following code: Rust Playground
I can spawn reading from File, but not for &[u8].
Two things I don't understand:
- How come File in 'test_file' satisfies
'static lifetime requirement?
- How can I call read on Vec (commented out
test_buffer function)? I can pass ownership to
transform() (i.e. I don't need it). Is the "solution" at the bottom the best option (admittedly not tested)?
Because it doesn't borrow anything.
T: 'static as a type bound means "you are allowed to keep it alive forever" (i.e., it doesn't contain temporary references, at most only
'static ones). Maybe your misunderstanding is that you expect it to mean "it necessarily lives forever", which it isn't.
You don't need to create a new wrapper type. The snippet compiles if you wrap the vector in an
This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.