diff options
Diffstat (limited to 'vendor/zerovec/src/ule')
-rw-r--r-- | vendor/zerovec/src/ule/mod.rs | 6 | ||||
-rw-r--r-- | vendor/zerovec/src/ule/option.rs | 2 | ||||
-rw-r--r-- | vendor/zerovec/src/ule/plain.rs | 19 | ||||
-rw-r--r-- | vendor/zerovec/src/ule/unvalidated.rs | 10 |
4 files changed, 14 insertions, 23 deletions
diff --git a/vendor/zerovec/src/ule/mod.rs b/vendor/zerovec/src/ule/mod.rs index 29c7d0ecd..e8ecd26e5 100644 --- a/vendor/zerovec/src/ule/mod.rs +++ b/vendor/zerovec/src/ule/mod.rs @@ -283,6 +283,12 @@ where /// "12.3e3" are logically equal, but not byte-for-byte equal, so we could define a canonical form /// where only a single digit is allowed before `.`. /// +/// There may also be cases where a `VarULE` has muiltiple canonical forms, such as a faster +/// version and a smaller version. The cleanest way to handle this case would be separate types. +/// However, if this is not feasible, then the application should ensure that the data it is +/// deserializing is in the expected form. For example, if the data is being loaded from an +/// external source, then requests could carry information about the expected form of the data. +/// /// Failure to follow this invariant will cause surprising behavior in `PartialEq`, which may /// result in unpredictable operations on `ZeroVec`, `VarZeroVec`, and `ZeroMap`. pub unsafe trait VarULE: 'static { diff --git a/vendor/zerovec/src/ule/option.rs b/vendor/zerovec/src/ule/option.rs index e1d2d25fa..a6b1966a5 100644 --- a/vendor/zerovec/src/ule/option.rs +++ b/vendor/zerovec/src/ule/option.rs @@ -22,7 +22,7 @@ use core::mem::{self, MaybeUninit}; /// Some('ł'), /// ]); /// -/// assert_eq!(z.get(2), Some(Some(('ø')))); +/// assert_eq!(z.get(2), Some(Some('ø'))); /// assert_eq!(z.get(3), Some(None)); /// ``` // Invariants: diff --git a/vendor/zerovec/src/ule/plain.rs b/vendor/zerovec/src/ule/plain.rs index 0b1bbb441..49455d45f 100644 --- a/vendor/zerovec/src/ule/plain.rs +++ b/vendor/zerovec/src/ule/plain.rs @@ -7,10 +7,7 @@ use super::*; use crate::ZeroSlice; -use core::{ - mem, - num::{NonZeroI8, NonZeroU8}, -}; +use core::num::{NonZeroI8, NonZeroU8}; /// A u8 array of little-endian data with infallible conversions to and from &[u8]. #[repr(transparent)] @@ -100,19 +97,7 @@ macro_rules! impl_const_constructors { let len = bytes.len(); #[allow(clippy::modulo_one)] if len % $size == 0 { - unsafe { - // Most of the slice manipulation functions are not yet const-stable, - // so we construct a slice with the right metadata and cast its type - // https://rust-lang.github.io/unsafe-code-guidelines/layout/pointers.html#notes - // - // Safety: - // * [u8] and [RawBytesULE<N>] have different lengths but the same alignment - // * ZeroSlice<$base> is repr(transparent) with [RawBytesULE<N>] - let [ptr, _]: [usize; 2] = mem::transmute(bytes); - let new_len = len / $size; - let raw = [ptr, new_len]; - Ok(mem::transmute(raw)) - } + Ok(unsafe { Self::from_bytes_unchecked(bytes) }) } else { Err(ZeroVecError::InvalidLength { ty: concat!("<const construct: ", $size, ">"), diff --git a/vendor/zerovec/src/ule/unvalidated.rs b/vendor/zerovec/src/ule/unvalidated.rs index a6ae55dcf..4564c8673 100644 --- a/vendor/zerovec/src/ule/unvalidated.rs +++ b/vendor/zerovec/src/ule/unvalidated.rs @@ -95,9 +95,9 @@ impl UnvalidatedStr { /// ``` /// use zerovec::ule::UnvalidatedStr; /// - /// static a: &UnvalidatedStr = UnvalidatedStr::from_bytes(b"abc"); + /// static A: &UnvalidatedStr = UnvalidatedStr::from_bytes(b"abc"); /// - /// let b = a.try_as_str().unwrap(); + /// let b = A.try_as_str().unwrap(); /// assert_eq!(b, "abc"); /// ``` // Note: this is const starting in 1.63 @@ -154,7 +154,7 @@ unsafe impl VarULE for UnvalidatedStr { } } -/// 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 #[cfg(feature = "serde")] impl serde::Serialize for UnvalidatedStr { fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> @@ -173,7 +173,7 @@ impl serde::Serialize for UnvalidatedStr { } } -/// 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 #[cfg(feature = "serde")] impl<'de> serde::Deserialize<'de> for Box<UnvalidatedStr> { fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> @@ -190,7 +190,7 @@ impl<'de> serde::Deserialize<'de> for Box<UnvalidatedStr> { } } -/// 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 #[cfg(feature = "serde")] impl<'de, 'a> serde::Deserialize<'de> for &'a UnvalidatedStr where |