There's a subtle lifetime issue created in the original code. The original code uses:
Bytes::from(&'static [u8])
from_raw_parts<'a, T>(*const T, usize) -> &'a [T]
Which requires the *const T pointer be a static pointer. Being provided through the FFI, this is unreasonable, and we should expect it to last only as long as the function call itself.
By simply replacing Bytes::from with Bytes::from_from_slice, we narrow down the lifetime from 'static to 'a, allowing for the underlying *const T pointer to be deallocated once the function has returned.
There's a subtle lifetime issue created in the original code. The original code uses:
Bytes::from(&'static [u8])
from_raw_parts<'a, T>(*const T, usize) -> &'a [T]
Which requires the
*const T
pointer be a static pointer. Being provided through the FFI, this is unreasonable, and we should expect it to last only as long as the function call itself.By simply replacing
Bytes::from
withBytes::from_from_slice
, we narrow down the lifetime from'static
to'a
, allowing for the underlying*const T
pointer to be deallocated once the function has returned.