I'm trying to understand why Rust makes a type have 'static
lifetime.
Please take a look at this code:
let tcp_tx_buffer = TcpSocketBuffer::new(vec![0; 128]);
VSCode tells me that the type of tcp_tx_buffer
is
smoltcp::storage::RingBuffer<'static, u8>
but if we find the new
method on RingBuffer
:
pub fn new<S>(storage: S) -> RingBuffer<'a, T>
where S: Into<ManagedSlice<'a, T>>,
{
RingBuffer {
storage: storage.into(),
read_at: 0,
length: 0,
}
}
there's no 'static
lifetime on the return. In fact the lifetime is the same as the input, 'a
. If let tcp_tx_buffer
were outside main
, I'd guess it's static
, but it has its own scope. Or does Rust consider main
to have a 'static
lifetime?