diff options
Diffstat (limited to 'vendor/zerovec/src')
-rw-r--r-- | vendor/zerovec/src/flexzerovec/serde.rs | 8 | ||||
-rw-r--r-- | vendor/zerovec/src/flexzerovec/slice.rs | 8 | ||||
-rw-r--r-- | vendor/zerovec/src/lib.rs | 9 | ||||
-rw-r--r-- | vendor/zerovec/src/map/borrowed.rs | 14 | ||||
-rw-r--r-- | vendor/zerovec/src/map/map.rs | 4 | ||||
-rw-r--r-- | vendor/zerovec/src/map/serde.rs | 8 | ||||
-rw-r--r-- | vendor/zerovec/src/map2d/borrowed.rs | 9 | ||||
-rw-r--r-- | vendor/zerovec/src/map2d/cursor.rs | 70 | ||||
-rw-r--r-- | vendor/zerovec/src/map2d/map.rs | 12 | ||||
-rw-r--r-- | vendor/zerovec/src/map2d/serde.rs | 8 | ||||
-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 | ||||
-rw-r--r-- | vendor/zerovec/src/varzerovec/serde.rs | 8 | ||||
-rw-r--r-- | vendor/zerovec/src/varzerovec/slice.rs | 28 | ||||
-rw-r--r-- | vendor/zerovec/src/varzerovec/vec.rs | 16 | ||||
-rw-r--r-- | vendor/zerovec/src/yoke_impls.rs | 14 | ||||
-rw-r--r-- | vendor/zerovec/src/zerovec/mod.rs | 7 | ||||
-rw-r--r-- | vendor/zerovec/src/zerovec/serde.rs | 10 | ||||
-rw-r--r-- | vendor/zerovec/src/zerovec/slice.rs | 30 |
21 files changed, 184 insertions, 116 deletions
diff --git a/vendor/zerovec/src/flexzerovec/serde.rs b/vendor/zerovec/src/flexzerovec/serde.rs index 44179be32..fb7caa7a8 100644 --- a/vendor/zerovec/src/flexzerovec/serde.rs +++ b/vendor/zerovec/src/flexzerovec/serde.rs @@ -42,7 +42,7 @@ impl<'de> Visitor<'de> for FlexZeroVecVisitor { } } -/// 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> Deserialize<'de> for FlexZeroVec<'a> where 'de: 'a, @@ -60,7 +60,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> Deserialize<'de> for &'a FlexZeroSlice where 'de: 'a, @@ -87,7 +87,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 Serialize for FlexZeroVec<'_> { fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where @@ -105,7 +105,7 @@ impl Serialize for FlexZeroVec<'_> { } } -/// 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 Serialize for FlexZeroSlice { fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where diff --git a/vendor/zerovec/src/flexzerovec/slice.rs b/vendor/zerovec/src/flexzerovec/slice.rs index 7cc6f12fa..ee164d05b 100644 --- a/vendor/zerovec/src/flexzerovec/slice.rs +++ b/vendor/zerovec/src/flexzerovec/slice.rs @@ -14,7 +14,6 @@ const USIZE_WIDTH: usize = mem::size_of::<usize>(); /// A zero-copy "slice" that efficiently represents `[usize]`. #[repr(packed)] -#[derive(Eq, PartialEq)] pub struct FlexZeroSlice { // Hard Invariant: 1 <= width <= USIZE_WIDTH (which is target_pointer_width) // Soft Invariant: width == the width of the largest element @@ -23,6 +22,13 @@ pub struct FlexZeroSlice { data: [u8], } +impl PartialEq for FlexZeroSlice { + fn eq(&self, other: &Self) -> bool { + self.width == other.width && self.data == other.data + } +} +impl Eq for FlexZeroSlice {} + /// Helper function to decode a little-endian "chunk" (byte slice of a specific length) /// into a `usize`. We cannot call `usize::from_le_bytes` directly because that function /// requires the high bits to be set to 0. diff --git a/vendor/zerovec/src/lib.rs b/vendor/zerovec/src/lib.rs index 9a37c762e..b8b292488 100644 --- a/vendor/zerovec/src/lib.rs +++ b/vendor/zerovec/src/lib.rs @@ -34,7 +34,7 @@ //! //! # Cargo features //! -//! This crate has five optional features: +//! This crate has several optional Cargo features: //! - `serde`: Allows serializing and deserializing `zerovec`'s abstractions via [`serde`](https://docs.rs/serde) //! - `yoke`: Enables implementations of `Yokeable` from the [`yoke`](https://docs.rs/yoke/) crate, which is also useful //! in situations involving a lot of zero-copy deserialization. @@ -270,6 +270,8 @@ pub mod maps { pub use crate::map2d::ZeroMap2dBorrowed; pub use crate::map::{MutableZeroVecLike, ZeroMapKV, ZeroVecLike}; + + pub use crate::map2d::ZeroMap2dCursor; } pub mod vecs { @@ -395,8 +397,9 @@ pub use zerovec_derive::make_ule; /// Generate a corresponding [`VarULE`] type and the relevant [`EncodeAsVarULE`]/[`zerofrom::ZeroFrom`] /// implementations for this type /// -/// This can be attached to structs containing only [`AsULE`] types with the last field being [`Cow<'a, str>`](alloc::borrow::Cow), -/// [`Cow<'a, str>`](alloc::borrow::Cow), [`ZeroSlice`], or [`VarZeroSlice`]. +/// This can be attached to structs containing only [`AsULE`] types with the last fields being +/// [`Cow<'a, str>`](alloc::borrow::Cow), [`ZeroSlice`], or [`VarZeroSlice`]. If there is more than one such field, it will be represented +/// using [`MultiFieldsULE`](crate::ule::MultiFieldsULE) and getters will be generated. /// /// The type must be [`PartialEq`] and [`Eq`]. /// diff --git a/vendor/zerovec/src/map/borrowed.rs b/vendor/zerovec/src/map/borrowed.rs index 4c1d1aef6..9d0854601 100644 --- a/vendor/zerovec/src/map/borrowed.rs +++ b/vendor/zerovec/src/map/borrowed.rs @@ -163,11 +163,6 @@ where /// let borrowed = map.as_borrowed(); /// assert_eq!(borrowed.get(&1), Some("one")); /// assert_eq!(borrowed.get(&3), None); - /// - /// let borrow = borrowed.get(&1); - /// drop(borrowed); - /// // still exists after the ZeroMapBorrowed has been dropped - /// assert_eq!(borrow, Some("one")); /// ``` pub fn get(&self, key: &K) -> Option<&'a V::GetType> { let index = self.keys.zvl_binary_search(key).ok()?; @@ -190,11 +185,6 @@ where /// let borrowed = map.as_borrowed(); /// assert_eq!(borrowed.get_by(|probe| probe.cmp(&1)), Some("one")); /// assert_eq!(borrowed.get_by(|probe| probe.cmp(&3)), None); - /// - /// let borrow = borrowed.get_by(|probe| probe.cmp(&1)); - /// drop(borrowed); - /// // still exists after the ZeroMapBorrowed has been dropped - /// assert_eq!(borrow, Some("one")); /// ``` pub fn get_by(&self, predicate: impl FnMut(&K) -> Ordering) -> Option<&'a V::GetType> { let index = self.keys.zvl_binary_search_by(predicate).ok()?; @@ -211,8 +201,8 @@ where /// map.insert(&1, "one"); /// map.insert(&2, "two"); /// let borrowed = map.as_borrowed(); - /// assert_eq!(borrowed.contains_key(&1), true); - /// assert_eq!(borrowed.contains_key(&3), false); + /// assert!(borrowed.contains_key(&1)); + /// assert!(!borrowed.contains_key(&3)); /// ``` pub fn contains_key(&self, key: &K) -> bool { self.keys.zvl_binary_search(key).is_ok() diff --git a/vendor/zerovec/src/map/map.rs b/vendor/zerovec/src/map/map.rs index 379b22667..692e265d6 100644 --- a/vendor/zerovec/src/map/map.rs +++ b/vendor/zerovec/src/map/map.rs @@ -194,8 +194,8 @@ where /// let mut map = ZeroMap::new(); /// map.insert(&1, "one"); /// map.insert(&2, "two"); - /// assert_eq!(map.contains_key(&1), true); - /// assert_eq!(map.contains_key(&3), false); + /// assert!(map.contains_key(&1)); + /// assert!(!map.contains_key(&3)); /// ``` pub fn contains_key(&self, key: &K) -> bool { self.keys.zvl_binary_search(key).is_ok() diff --git a/vendor/zerovec/src/map/serde.rs b/vendor/zerovec/src/map/serde.rs index dbe4b433d..e82886d2a 100644 --- a/vendor/zerovec/src/map/serde.rs +++ b/vendor/zerovec/src/map/serde.rs @@ -9,7 +9,7 @@ use serde::de::{self, Deserialize, Deserializer, MapAccess, SeqAccess, Visitor}; #[cfg(feature = "serde")] use serde::ser::{Serialize, SerializeMap, SerializeSeq, Serializer}; -/// 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<'a, K, V> Serialize for ZeroMap<'a, K, V> where @@ -49,7 +49,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 #[cfg(feature = "serde")] impl<'a, K, V> Serialize for ZeroMapBorrowed<'a, K, V> where @@ -158,7 +158,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, K, V> Deserialize<'de> for ZeroMap<'a, K, V> where K: ZeroMapKV<'a> + Ord + ?Sized, @@ -190,7 +190,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, K, V> Deserialize<'de> for ZeroMapBorrowed<'a, K, V> where K: ZeroMapKV<'a> + Ord + ?Sized, diff --git a/vendor/zerovec/src/map2d/borrowed.rs b/vendor/zerovec/src/map2d/borrowed.rs index d9972fae9..209da299b 100644 --- a/vendor/zerovec/src/map2d/borrowed.rs +++ b/vendor/zerovec/src/map2d/borrowed.rs @@ -199,11 +199,6 @@ where /// assert_eq!(borrowed.get_2d(&2, "one"), Some("bar")); /// assert_eq!(borrowed.get_2d(&2, "two"), Some("baz")); /// assert_eq!(borrowed.get_2d(&3, "three"), None); - /// - /// let borrow = borrowed.get_2d(&1, "one"); - /// drop(borrowed); - /// // still exists after the ZeroMap2dBorrowed has been dropped - /// assert_eq!(borrow, Some("foo")); /// ``` pub fn get_2d(&self, key0: &K0, key1: &K1) -> Option<&'a V::GetType> { self.get0(key0)?.get1(key1) @@ -270,8 +265,8 @@ where /// map.insert(&1, "one", "foo"); /// map.insert(&2, "two", "bar"); /// let borrowed = map.as_borrowed(); - /// assert_eq!(borrowed.contains_key0(&1), true); - /// assert_eq!(borrowed.contains_key0(&3), false); + /// assert!(borrowed.contains_key0(&1)); + /// assert!(!borrowed.contains_key0(&3)); /// ``` pub fn contains_key0(&self, key0: &K0) -> bool { self.keys0.zvl_binary_search(key0).is_ok() diff --git a/vendor/zerovec/src/map2d/cursor.rs b/vendor/zerovec/src/map2d/cursor.rs index 0654ee794..4802187be 100644 --- a/vendor/zerovec/src/map2d/cursor.rs +++ b/vendor/zerovec/src/map2d/cursor.rs @@ -92,7 +92,9 @@ where self.keys0.zvl_get(self.key0_index).unwrap() } - /// Borrow an ordered iterator over keys1 for a particular key0. + /// Borrow an ordered iterator over keys1 and values for a particular key0. + /// + /// To get the values as copy types, see [`Self::iter1_copied`]. /// /// For an example, see [`ZeroMap2d::iter0()`]. pub fn iter1( @@ -153,6 +155,64 @@ where impl<'l, 'a, K0, K1, V> ZeroMap2dCursor<'l, 'a, K0, K1, V> where K0: ZeroMapKV<'a>, + K1: ZeroMapKV<'a>, + V: ZeroMapKV<'a>, + K0: ?Sized, + K1: ?Sized, + V: Copy, +{ + /// Borrow an ordered iterator over keys1 and values for a particular key0. + /// + /// The values are returned as copy types. + /// + /// # Examples + /// + /// ``` + /// use zerovec::ZeroMap2d; + /// + /// let zm2d: ZeroMap2d<str, u8, usize> = [ + /// ("a", 0u8, 1usize), + /// ("b", 1u8, 1000usize), + /// ("b", 2u8, 2000usize), + /// ] + /// .into_iter() + /// .collect(); + /// + /// let mut total_value = 0; + /// + /// for cursor in zm2d.iter0() { + /// for (_, value) in cursor.iter1_copied() { + /// total_value += value; + /// } + /// } + /// + /// assert_eq!(total_value, 3001); + /// ``` + pub fn iter1_copied( + &self, + ) -> impl Iterator<Item = (&'l <K1 as ZeroMapKV<'a>>::GetType, V)> + '_ { + let range = self.get_range(); + #[allow(clippy::unwrap_used)] // `self.get_range()` returns a valid range + range.map(move |idx| { + ( + self.keys1.zvl_get(idx).unwrap(), + self.get1_copied_at(idx).unwrap(), + ) + }) + } + + fn get1_copied_at(&self, index: usize) -> Option<V> { + let ule = self.values.zvl_get(index)?; + let mut result = Option::<V>::None; + V::Container::zvl_get_as_t(ule, |v| result.replace(*v)); + #[allow(clippy::unwrap_used)] // `zvl_get_as_t` guarantees that the callback is invoked + Some(result.unwrap()) + } +} + +impl<'l, 'a, K0, K1, V> ZeroMap2dCursor<'l, 'a, K0, K1, V> +where + K0: ZeroMapKV<'a>, K1: ZeroMapKV<'a> + Ord, V: ZeroMapKV<'a>, K0: ?Sized, @@ -253,14 +313,6 @@ where let key1_index = self.get_key1_index_by(predicate)?; self.get1_copied_at(key1_index) } - - fn get1_copied_at(&self, index: usize) -> Option<V> { - let ule = self.values.zvl_get(index)?; - let mut result = Option::<V>::None; - V::Container::zvl_get_as_t(ule, |v| result.replace(*v)); - #[allow(clippy::unwrap_used)] // `zvl_get_as_t` guarantees that the callback is invoked - Some(result.unwrap()) - } } // We can't use the default PartialEq because ZeroMap2d is invariant diff --git a/vendor/zerovec/src/map2d/map.rs b/vendor/zerovec/src/map2d/map.rs index ab6eded4e..e6545dfa5 100644 --- a/vendor/zerovec/src/map2d/map.rs +++ b/vendor/zerovec/src/map2d/map.rs @@ -534,8 +534,8 @@ where /// let mut map = ZeroMap2d::new(); /// map.insert(&1, "one", "foo"); /// map.insert(&2, "two", "bar"); - /// assert_eq!(map.contains_key0(&1), true); - /// assert_eq!(map.contains_key0(&3), false); + /// assert!(map.contains_key0(&1)); + /// assert!(!map.contains_key0(&3)); /// ``` pub fn contains_key0(&self, key0: &K0) -> bool { self.keys0.zvl_binary_search(key0).is_ok() @@ -814,13 +814,13 @@ mod test { // Remove some elements let result = zm2d.remove(&3, "ccc"); // first element - assert_eq!(result, Some(String::from("CCC").into_boxed_str())); + assert_eq!(result.as_deref(), Some("CCC")); let result = zm2d.remove(&3, "mmm"); // middle element - assert_eq!(result, Some(String::from("MM0").into_boxed_str())); + assert_eq!(result.as_deref(), Some("MM0")); let result = zm2d.remove(&5, "ddd"); // singleton K0 - assert_eq!(result, Some(String::from("DD1").into_boxed_str())); + assert_eq!(result.as_deref(), Some("DD1")); let result = zm2d.remove(&9, "yyy"); // last element - assert_eq!(result, Some(String::from("YYY").into_boxed_str())); + assert_eq!(result.as_deref(), Some("YYY")); assert_eq!(format!("{:?}", zm2d), "ZeroMap2d { keys0: ZeroVec([3, 6, 7]), joiner: ZeroVec([1, 4, 7]), keys1: [\"eee\", \"ddd\", \"mmm\", \"nnn\", \"ddd\", \"eee\", \"www\"], values: [\"EEE\", \"DD3\", \"MM1\", \"NNN\", \"DD2\", \"EEE\", \"WWW\"] }"); } diff --git a/vendor/zerovec/src/map2d/serde.rs b/vendor/zerovec/src/map2d/serde.rs index f8b5f147b..b5e913654 100644 --- a/vendor/zerovec/src/map2d/serde.rs +++ b/vendor/zerovec/src/map2d/serde.rs @@ -12,7 +12,7 @@ use serde::de::{self, Deserialize, Deserializer, MapAccess, Visitor}; #[cfg(feature = "serde")] use serde::ser::{Serialize, SerializeMap, Serializer}; -/// 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<'a, K0, K1, V> Serialize for ZeroMap2d<'a, K0, K1, V> where @@ -75,7 +75,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 #[cfg(feature = "serde")] impl<'a, K0, K1, V> Serialize for ZeroMap2dBorrowed<'a, K0, K1, V> where @@ -220,7 +220,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, K0, K1, V> Deserialize<'de> for ZeroMap2d<'a, K0, K1, V> where K0: ZeroMapKV<'a> + Ord + ?Sized, @@ -287,7 +287,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, K0, K1, V> Deserialize<'de> for ZeroMap2dBorrowed<'a, K0, K1, V> where K0: ZeroMapKV<'a> + Ord + ?Sized, 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 diff --git a/vendor/zerovec/src/varzerovec/serde.rs b/vendor/zerovec/src/varzerovec/serde.rs index dd6e863ff..649b29cfb 100644 --- a/vendor/zerovec/src/varzerovec/serde.rs +++ b/vendor/zerovec/src/varzerovec/serde.rs @@ -60,7 +60,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, F> Deserialize<'de> for VarZeroVec<'a, T, F> where T: VarULE + ?Sized, @@ -81,7 +81,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, F> Deserialize<'de> for &'a VarZeroSlice<T, F> where T: VarULE + ?Sized, @@ -111,7 +111,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 #[cfg(feature = "serde")] impl<T, F> Serialize for VarZeroVec<'_, T, F> where @@ -134,7 +134,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 #[cfg(feature = "serde")] impl<T, F> Serialize for VarZeroSlice<T, F> where diff --git a/vendor/zerovec/src/varzerovec/slice.rs b/vendor/zerovec/src/varzerovec/slice.rs index 59e8da03f..afdbe80d9 100644 --- a/vendor/zerovec/src/varzerovec/slice.rs +++ b/vendor/zerovec/src/varzerovec/slice.rs @@ -29,8 +29,13 @@ use core::ops::Range; /// The `F` type parameter is a [`VarZeroVecFormat`] (see its docs for more details), which can be used to select the /// precise format of the backing buffer with various size and performance tradeoffs. It defaults to [`Index16`]. /// -/// This type can be nested within itself to allow for multi-level nested `Vec`s, for -/// example the following code constructs the conceptual zero-copy equivalent of `Vec<Vec<Vec<str>>>` +/// This type can be nested within itself to allow for multi-level nested `Vec`s. +/// +/// # Examples +/// +/// ## Nested Slices +/// +/// The following code constructs the conceptual zero-copy equivalent of `Vec<Vec<Vec<str>>>` /// /// ```rust /// use zerovec::ule::*; @@ -71,6 +76,25 @@ use core::ops::Range; /// VarZeroVec::parse_byte_slice(bytes).unwrap(); /// assert_eq!(vzv_from_bytes, vzv_all); /// ``` +/// +/// ## Iterate over Windows +/// +/// Although [`VarZeroSlice`] does not itself have a `.windows` iterator like +/// [core::slice::Windows], this behavior can be easily modeled using an iterator: +/// +/// ``` +/// use zerovec::VarZeroVec; +/// +/// let vzv = VarZeroVec::<str>::from(&["a", "b", "c", "d"]); +/// # let mut pairs: Vec<(&str, &str)> = Vec::new(); +/// +/// let mut it = vzv.iter().peekable(); +/// while let (Some(x), Some(y)) = (it.next(), it.peek()) { +/// // Evaluate (x, y) here. +/// # pairs.push((x, y)); +/// } +/// # assert_eq!(pairs, &[("a", "b"), ("b", "c"), ("c", "d")]); +/// ``` // // safety invariant: The slice MUST be one which parses to // a valid VarZeroVecComponents<T> diff --git a/vendor/zerovec/src/varzerovec/vec.rs b/vendor/zerovec/src/varzerovec/vec.rs index 031da6453..7edb48a96 100644 --- a/vendor/zerovec/src/varzerovec/vec.rs +++ b/vendor/zerovec/src/varzerovec/vec.rs @@ -11,7 +11,7 @@ use core::ops::Deref; use super::*; -/// A zero-copy vector for variable-width types. +/// A zero-copy, byte-aligned vector for variable-width types. /// /// `VarZeroVec<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, and @@ -39,6 +39,20 @@ use super::*; /// The `F` type parameter is a [`VarZeroVecFormat`] (see its docs for more details), which can be used to select the /// precise format of the backing buffer with various size and performance tradeoffs. It defaults to [`Index16`]. /// +/// # Bytes and Equality +/// +/// Two [`VarZeroVec`]s are equal if and only if their bytes are equal, as described in the trait +/// [`VarULE`]. However, we do not guarantee stability of byte equality or serialization format +/// across major SemVer releases. +/// +/// To compare a [`Vec<T>`] to a [`VarZeroVec<T>`], it is generally recommended to use +/// [`Iterator::eq`], since it is somewhat expensive at runtime to convert from a [`Vec<T>`] to a +/// [`VarZeroVec<T>`] or vice-versa. +/// +/// Prior to zerovec reaching 1.0, the precise byte representation of [`VarZeroVec`] is still +/// under consideration, with different options along the space-time spectrum. See +/// [#1410](https://github.com/unicode-org/icu4x/issues/1410). +/// /// # Example /// /// ```rust diff --git a/vendor/zerovec/src/yoke_impls.rs b/vendor/zerovec/src/yoke_impls.rs index 81fc22c74..0efb47a2d 100644 --- a/vendor/zerovec/src/yoke_impls.rs +++ b/vendor/zerovec/src/yoke_impls.rs @@ -15,7 +15,7 @@ use core::{mem, ptr}; use yoke::*; // This impl is similar to the impl on Cow and is safe for the same reasons -/// This impl can be made available by enabling the optional `yoke` feature of the `zerovec` crate +/// This impl requires enabling the optional `yoke` Cargo feature of the `zerovec` crate unsafe impl<'a, T: 'static + AsULE + ?Sized> Yokeable<'a> for ZeroVec<'static, T> { type Output = ZeroVec<'a, T>; #[inline] @@ -43,7 +43,7 @@ unsafe impl<'a, T: 'static + AsULE + ?Sized> Yokeable<'a> for ZeroVec<'static, T } // This impl is similar to the impl on Cow and is safe for the same reasons -/// This impl can be made available by enabling the optional `yoke` feature of the `zerovec` crate +/// This impl requires enabling the optional `yoke` Cargo feature of the `zerovec` crate unsafe impl<'a, T: 'static + VarULE + ?Sized> Yokeable<'a> for VarZeroVec<'static, T> { type Output = VarZeroVec<'a, T>; #[inline] @@ -71,7 +71,7 @@ unsafe impl<'a, T: 'static + VarULE + ?Sized> Yokeable<'a> for VarZeroVec<'stati } // This impl is similar to the impl on Cow and is safe for the same reasons -/// This impl can be made available by enabling the optional `yoke` feature of the `zerovec` crate +/// This impl requires enabling the optional `yoke` Cargo feature of the `zerovec` crate unsafe impl<'a> Yokeable<'a> for FlexZeroVec<'static> { type Output = FlexZeroVec<'a>; #[inline] @@ -98,7 +98,7 @@ unsafe impl<'a> Yokeable<'a> for FlexZeroVec<'static> { } } -/// This impl can be made available by enabling the optional `yoke` feature of the `zerovec` crate +/// This impl requires enabling the optional `yoke` Cargo feature of the `zerovec` crate #[allow(clippy::transmute_ptr_to_ptr)] unsafe impl<'a, K, V> Yokeable<'a> for ZeroMap<'static, K, V> where @@ -144,7 +144,7 @@ where } } -/// This impl can be made available by enabling the optional `yoke` feature of the `zerovec` crate +/// This impl requires enabling the optional `yoke` Cargo feature of the `zerovec` crate #[allow(clippy::transmute_ptr_to_ptr)] unsafe impl<'a, K, V> Yokeable<'a> for ZeroMapBorrowed<'static, K, V> where @@ -190,7 +190,7 @@ where } } -/// This impl can be made available by enabling the optional `yoke` feature of the `zerovec` crate +/// This impl requires enabling the optional `yoke` Cargo feature of the `zerovec` crate #[allow(clippy::transmute_ptr_to_ptr)] unsafe impl<'a, K0, K1, V> Yokeable<'a> for ZeroMap2d<'static, K0, K1, V> where @@ -238,7 +238,7 @@ where } } -/// This impl can be made available by enabling the optional `yoke` feature of the `zerovec` crate +/// This impl requires enabling the optional `yoke` Cargo feature of the `zerovec` crate #[allow(clippy::transmute_ptr_to_ptr)] unsafe impl<'a, K0, K1, V> Yokeable<'a> for ZeroMap2dBorrowed<'static, K0, K1, V> where 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] |