Skip to content

Commit

Permalink
feat: remove bytemuck depedency
Browse files Browse the repository at this point in the history
  • Loading branch information
wyfo committed Sep 27, 2024
1 parent 1b80456 commit 8362a22
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 11 deletions.
7 changes: 0 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ async-trait = "0.1.82"
base64 = "0.22.1"
bincode = "1.3.3"
bytes = "1.7.1"
bytemuck = "1"
clap = { version = "4.5.17", features = ["derive"] }
console-subscriber = "0.4.0"
const_format = "0.2.33"
Expand Down
1 change: 0 additions & 1 deletion zenoh-ext/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ tokio = { workspace = true, features = [
"io-std",
] }
bincode = { workspace = true }
bytemuck = { workspace = true }
zenoh-util = { workspace = true }
flume = { workspace = true }
futures = { workspace = true }
Expand Down
28 changes: 26 additions & 2 deletions zenoh-ext/src/serialization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -368,8 +368,32 @@ impl_tuple!(
#[repr(transparent)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct VarInt<T>(pub T);

unsafe impl<T> bytemuck::TransparentWrapper<T> for VarInt<T> {}
impl<T> VarInt<T> {
pub fn from_ref(int: &T) -> &Self {
// SAFETY: `VarInt` is `repr(transparent)`
unsafe { &*(int as *const T as *const Self) }
}
pub fn from_mut(int: &mut T) -> &mut Self {
// SAFETY: `VarInt` is `repr(transparent)`
unsafe { &mut *(int as *mut T as *mut Self) }
}
pub fn slice_from_ref(slice: &[T]) -> &[Self] {
// SAFETY: `VarInt` is `repr(transparent)`
unsafe { &*(slice as *const [T] as *const [Self]) }
}
pub fn slice_from_mut(slice: &mut [T]) -> &mut [Self] {
// SAFETY: `VarInt` is `repr(transparent)`
unsafe { &mut *(slice as *mut [T] as *mut [Self]) }
}
pub fn slice_into_ref(slice: &[Self]) -> &[T] {
// SAFETY: `VarInt` is `repr(transparent)`
unsafe { &*(slice as *const [Self] as *const [T]) }
}
pub fn slice_into_mut(slice: &mut [Self]) -> &mut [T] {
// SAFETY: `VarInt` is `repr(transparent)`
unsafe { &mut *(slice as *mut [Self] as *mut [T]) }
}
}
impl<T> Deref for VarInt<T> {
type Target = T;

Expand Down

0 comments on commit 8362a22

Please sign in to comment.