diff --git a/src/collections.rs b/src/collections.rs index 5037e2b0b..04c69cbc4 100644 --- a/src/collections.rs +++ b/src/collections.rs @@ -254,6 +254,13 @@ impl From> for CSliceOwned { } } +impl From> for CSliceOwned { + fn from(value: Box<[u8]>) -> Self { + let slice = Box::leak(value); + CSliceOwned(CSlice::wrap(slice.as_ptr(), slice.len())) + } +} + impl From> for CSlice { fn from(value: Vec) -> Self { let slice: CSliceOwned = value.into(); diff --git a/src/zbytes.rs b/src/zbytes.rs index 5cc2eb874..94f4aaa51 100644 --- a/src/zbytes.rs +++ b/src/zbytes.rs @@ -136,7 +136,7 @@ pub unsafe extern "C" fn z_bytes_to_slice( ) -> z_result_t { let payload = this.as_rust_type_ref(); dst.as_rust_type_mut_uninit() - .write(payload.to_bytes().into_owned().into()); + .write(CSliceOwned::from(Box::<[u8]>::from(payload.to_bytes()))); result::Z_OK }