Closed
Description
Recently I've encountered a problem, when I wanted to return a slice of bytes in an integer:
fn to_bytes(num: &u32) -> &[u8] {
&u32::to_le_bytes(*num)
}
(This is an oversimplification of the original code, which is generic over every integer type along with other stuff)
Obviously, since to_le_bytes(*num)
is dropped when the function returns, this piece of code failed the borrow check. Hence my need for as_le_bytes(num)
, as num
is actually alive all this time!