summaryrefslogtreecommitdiffstats
path: root/vendor/zerovec/src/zerovec
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/zerovec/src/zerovec')
-rw-r--r--vendor/zerovec/src/zerovec/mod.rs7
-rw-r--r--vendor/zerovec/src/zerovec/serde.rs10
-rw-r--r--vendor/zerovec/src/zerovec/slice.rs30
3 files changed, 20 insertions, 27 deletions
diff --git a/vendor/zerovec/src/zerovec/mod.rs b/vendor/zerovec/src/zerovec/mod.rs
index e0876338f..371450e21 100644
--- a/vendor/zerovec/src/zerovec/mod.rs
+++ b/vendor/zerovec/src/zerovec/mod.rs
@@ -22,7 +22,7 @@ use core::marker::PhantomData;
use core::mem;
use core::ops::Deref;
-/// A zero-copy vector for fixed-width types.
+/// A zero-copy, byte-aligned vector for fixed-width types.
///
/// `ZeroVec<T>` is designed as a drop-in replacement for `Vec<T>` in situations where it is
/// desirable to borrow data from an unaligned byte slice, such as zero-copy deserialization.
@@ -352,11 +352,6 @@ where
/// `bytes` need to be an output from [`ZeroSlice::as_bytes()`].
pub const unsafe fn from_bytes_unchecked(bytes: &'a [u8]) -> Self {
// &[u8] and &[T::ULE] are the same slice with different length metadata.
- /// core::slice::from_raw_parts(a, b) = core::mem::transmute((a, b)) hack
- /// ```compile_fail
- /// const unsafe fn canary() { core::slice::from_raw_parts(0 as *const u8, 0); }
- /// ```
- const _: () = ();
Self::new_borrowed(core::mem::transmute((
bytes.as_ptr(),
bytes.len() / core::mem::size_of::<T::ULE>(),
diff --git a/vendor/zerovec/src/zerovec/serde.rs b/vendor/zerovec/src/zerovec/serde.rs
index 8250fc20a..e3141071c 100644
--- a/vendor/zerovec/src/zerovec/serde.rs
+++ b/vendor/zerovec/src/zerovec/serde.rs
@@ -58,7 +58,7 @@ where
}
}
-/// This impl can be made available by enabling the optional `serde` feature of the `zerovec` crate
+/// This impl requires enabling the optional `serde` Cargo feature of the `zerovec` crate
impl<'de, 'a, T> Deserialize<'de> for ZeroVec<'a, T>
where
T: 'de + Deserialize<'de> + AsULE,
@@ -77,7 +77,7 @@ where
}
}
-/// This impl can be made available by enabling the optional `serde` feature of the `zerovec` crate
+/// This impl requires enabling the optional `serde` Cargo feature of the `zerovec` crate
impl<T> Serialize for ZeroVec<'_, T>
where
T: Serialize + AsULE,
@@ -98,7 +98,7 @@ where
}
}
-/// This impl can be made available by enabling the optional `serde` feature of the `zerovec` crate
+/// This impl requires enabling the optional `serde` Cargo feature of the `zerovec` crate
impl<'de, T> Deserialize<'de> for Box<ZeroSlice<T>>
where
T: Deserialize<'de> + AsULE + 'static,
@@ -113,7 +113,7 @@ where
}
}
-/// This impl can be made available by enabling the optional `serde` feature of the `zerovec` crate
+/// This impl requires enabling the optional `serde` Cargo feature of the `zerovec` crate
impl<'de, 'a, T> Deserialize<'de> for &'a ZeroSlice<T>
where
T: Deserialize<'de> + AsULE + 'static,
@@ -141,7 +141,7 @@ where
}
}
-/// This impl can be made available by enabling the optional `serde` feature of the `zerovec` crate
+/// This impl requires enabling the optional `serde` Cargo feature of the `zerovec` crate
impl<T> Serialize for ZeroSlice<T>
where
T: Serialize + AsULE,
diff --git a/vendor/zerovec/src/zerovec/slice.rs b/vendor/zerovec/src/zerovec/slice.rs
index ce27a15b2..847705304 100644
--- a/vendor/zerovec/src/zerovec/slice.rs
+++ b/vendor/zerovec/src/zerovec/slice.rs
@@ -65,12 +65,10 @@ where
/// `bytes` need to be an output from [`ZeroSlice::as_bytes()`].
pub const unsafe fn from_bytes_unchecked(bytes: &[u8]) -> &Self {
// &[u8] and &[T::ULE] are the same slice with different length metadata.
- /// core::slice::from_raw_parts(a, b) = core::mem::transmute((a, b)) hack
- /// ```compile_fail
- /// const unsafe fn canary() { core::slice::from_raw_parts(0 as *const u8, 0); }
- /// ```
- const _: () = ();
- core::mem::transmute((bytes.as_ptr(), bytes.len() / core::mem::size_of::<T::ULE>()))
+ Self::from_ule_slice(core::mem::transmute((
+ bytes.as_ptr(),
+ bytes.len() / core::mem::size_of::<T::ULE>(),
+ )))
}
/// Construct a `&ZeroSlice<T>` from a slice of ULEs.
@@ -235,17 +233,17 @@ where
/// ```
/// use zerovec::ZeroSlice;
///
- /// const bytes: &[u8] = &[0xD3, 0x00, 0x19, 0x01, 0xA5, 0x01, 0xCD, 0x80];
- /// const zs_u16: &ZeroSlice<u16> = {
- /// match ZeroSlice::<u16>::try_from_bytes(bytes) {
+ /// const BYTES: &[u8] = &[0xD3, 0x00, 0x19, 0x01, 0xA5, 0x01, 0xCD, 0x80];
+ /// const ZS_U16: &ZeroSlice<u16> = {
+ /// match ZeroSlice::<u16>::try_from_bytes(BYTES) {
/// Ok(s) => s,
/// Err(_) => unreachable!(),
/// }
/// };
///
- /// let zs_i16: &ZeroSlice<i16> = zs_u16.cast();
+ /// let zs_i16: &ZeroSlice<i16> = ZS_U16.cast();
///
- /// assert_eq!(zs_u16.get(3), Some(32973));
+ /// assert_eq!(ZS_U16.get(3), Some(32973));
/// assert_eq!(zs_i16.get(3), Some(-32563));
/// ```
#[inline]
@@ -268,18 +266,18 @@ where
/// ```
/// use zerovec::ZeroSlice;
///
- /// const bytes: &[u8] = &[0x7F, 0xF3, 0x01, 0x00, 0x49, 0xF6, 0x01, 0x00];
- /// const zs_u32: &ZeroSlice<u32> = {
- /// match ZeroSlice::<u32>::try_from_bytes(bytes) {
+ /// const BYTES: &[u8] = &[0x7F, 0xF3, 0x01, 0x00, 0x49, 0xF6, 0x01, 0x00];
+ /// const ZS_U32: &ZeroSlice<u32> = {
+ /// match ZeroSlice::<u32>::try_from_bytes(BYTES) {
/// Ok(s) => s,
/// Err(_) => unreachable!(),
/// }
/// };
///
/// let zs_u8_4: &ZeroSlice<[u8; 4]> =
- /// zs_u32.try_as_converted().expect("valid code points");
+ /// ZS_U32.try_as_converted().expect("valid code points");
///
- /// assert_eq!(zs_u32.get(0), Some(127871));
+ /// assert_eq!(ZS_U32.get(0), Some(127871));
/// assert_eq!(zs_u8_4.get(0), Some([0x7F, 0xF3, 0x01, 0x00]));
/// ```
#[inline]