#[repr(C)]
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
pub struct ByteSlice {
pub start: *mut u8,
pub length: usize,
}
impl ByteSlice {
pub const INVALID: ByteSlice = ByteSlice {
start: std::ptr::null_mut(),
length: 0,
};
pub(crate) unsafe fn as_slice(&self) -> &[u8] {
assert!(!self.start.is_null());
unsafe { std::slice::from_raw_parts(self.start, self.length) }
}
#[allow(
clippy::mut_from_ref,
reason = "This is used to get a pointer from the C side."
)]
pub(crate) unsafe fn as_slice_mut(&self) -> &mut [u8] {
unsafe { std::slice::from_raw_parts_mut(self.start, self.length) }
}
pub(crate) unsafe fn from_slice(slice: &mut [u8]) -> Self {
Self {
start: slice.as_mut_ptr(),
length: slice.len(),
}
}
}