diff options
Diffstat (limited to 'vendor/zerovec/src/varzerovec')
-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 |
3 files changed, 45 insertions, 7 deletions
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 |