pub struct VarZeroVecOwned<T: ?Sized, F = Index16> { /* private fields */ }
Expand description
A fully-owned VarZeroVec
. This type has no lifetime but has the same
internal buffer representation of VarZeroVec
, making it cheaply convertible to
VarZeroVec
and VarZeroSlice
.
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
.
Implementations§
Source§impl<T: VarULE + ?Sized, F> VarZeroVecOwned<T, F>
impl<T: VarULE + ?Sized, F> VarZeroVecOwned<T, F>
Source§impl<T: VarULE + ?Sized, F: VarZeroVecFormat> VarZeroVecOwned<T, F>
impl<T: VarULE + ?Sized, F: VarZeroVecFormat> VarZeroVecOwned<T, F>
Sourcepub fn from_slice(slice: &VarZeroSlice<T, F>) -> Self
pub fn from_slice(slice: &VarZeroSlice<T, F>) -> Self
Construct a VarZeroVecOwned from a VarZeroSlice
by cloning the internal data
Sourcepub fn try_from_elements<A>(elements: &[A]) -> Result<Self, &'static str>where
A: EncodeAsVarULE<T>,
pub fn try_from_elements<A>(elements: &[A]) -> Result<Self, &'static str>where
A: EncodeAsVarULE<T>,
Construct a VarZeroVecOwned from a list of elements
Sourcepub fn as_slice(&self) -> &VarZeroSlice<T, F>
pub fn as_slice(&self) -> &VarZeroSlice<T, F>
Obtain this VarZeroVec
as a VarZeroSlice
Sourcepub fn as_varzerovec<'a>(&'a self) -> VarZeroVec<'a, T, F>
pub fn as_varzerovec<'a>(&'a self) -> VarZeroVec<'a, T, F>
Get this VarZeroVecOwned
as a borrowed VarZeroVec
If you wish to repeatedly call methods on this VarZeroVecOwned
,
it is more efficient to perform this conversion first
Sourcepub fn into_bytes(self) -> Vec<u8>
pub fn into_bytes(self) -> Vec<u8>
Consume this vector and return the backing buffer
Sourcepub fn push<A: EncodeAsVarULE<T> + ?Sized>(&mut self, element: &A)
pub fn push<A: EncodeAsVarULE<T> + ?Sized>(&mut self, element: &A)
Insert an element at the end of this vector
Methods from Deref<Target = VarZeroSlice<T, F>>§
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Get the number of elements in this slice
§Example
let strings = vec!["foo", "bar", "baz", "quux"];
let vec = VarZeroVec::<str>::from(&strings);
assert_eq!(vec.len(), 4);
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns true
if the slice contains no elements.
§Examples
let strings: Vec<String> = vec![];
let vec = VarZeroVec::<str>::from(&strings);
assert!(vec.is_empty());
Sourcepub fn iter<'b>(&'b self) -> impl Iterator<Item = &'b T>
pub fn iter<'b>(&'b self) -> impl Iterator<Item = &'b T>
Obtain an iterator over this slice’s elements
§Example
let strings = vec!["foo", "bar", "baz", "quux"];
let vec = VarZeroVec::<str>::from(&strings);
let mut iter_results: Vec<&str> = vec.iter().collect();
assert_eq!(iter_results[0], "foo");
assert_eq!(iter_results[1], "bar");
assert_eq!(iter_results[2], "baz");
assert_eq!(iter_results[3], "quux");
Sourcepub fn get(&self, idx: usize) -> Option<&T>
pub fn get(&self, idx: usize) -> Option<&T>
Get one of this slice’s elements, returning None
if the index is out of bounds
§Example
let strings = vec!["foo", "bar", "baz", "quux"];
let vec = VarZeroVec::<str>::from(&strings);
let mut iter_results: Vec<&str> = vec.iter().collect();
assert_eq!(vec.get(0), Some("foo"));
assert_eq!(vec.get(1), Some("bar"));
assert_eq!(vec.get(2), Some("baz"));
assert_eq!(vec.get(3), Some("quux"));
assert_eq!(vec.get(4), None);
Sourcepub unsafe fn get_unchecked(&self, idx: usize) -> &T
pub unsafe fn get_unchecked(&self, idx: usize) -> &T
Get one of this slice’s elements
§Safety
index
must be in range
§Example
let strings = vec!["foo", "bar", "baz", "quux"];
let vec = VarZeroVec::<str>::from(&strings);
let mut iter_results: Vec<&str> = vec.iter().collect();
unsafe {
assert_eq!(vec.get_unchecked(0), "foo");
assert_eq!(vec.get_unchecked(1), "bar");
assert_eq!(vec.get_unchecked(2), "baz");
assert_eq!(vec.get_unchecked(3), "quux");
}
Sourcepub fn as_bytes(&self) -> &[u8]
pub fn as_bytes(&self) -> &[u8]
Get a reference to the entire encoded backing buffer of this slice
The bytes can be passed back to Self::parse_byte_slice()
.
To take the bytes as a vector, see VarZeroVec::into_bytes()
.
§Example
let strings = vec!["foo", "bar", "baz"];
let vzv = VarZeroVec::<str>::from(&strings);
assert_eq!(vzv, VarZeroVec::parse_byte_slice(vzv.as_bytes()).unwrap());
Sourcepub fn as_varzerovec<'a>(&'a self) -> VarZeroVec<'a, T, F>
pub fn as_varzerovec<'a>(&'a self) -> VarZeroVec<'a, T, F>
Get this VarZeroSlice
as a borrowed VarZeroVec
If you wish to repeatedly call methods on this VarZeroSlice
,
it is more efficient to perform this conversion first
Sourcepub fn binary_search(&self, x: &T) -> Result<usize, usize>
pub fn binary_search(&self, x: &T) -> Result<usize, usize>
Binary searches a sorted VarZeroVec<T>
for the given element. For more information, see
the standard library function binary_search
.
§Example
let strings = vec!["a", "b", "f", "g"];
let vec = VarZeroVec::<str>::from(&strings);
assert_eq!(vec.binary_search("f"), Ok(2));
assert_eq!(vec.binary_search("e"), Err(2));
Sourcepub fn binary_search_in_range(
&self,
x: &T,
range: Range<usize>,
) -> Option<Result<usize, usize>>
pub fn binary_search_in_range( &self, x: &T, range: Range<usize>, ) -> Option<Result<usize, usize>>
Binary searches a VarZeroVec<T>
for the given element within a certain sorted range.
If the range is out of bounds, returns None
. Otherwise, returns a Result
according
to the behavior of the standard library function binary_search
.
The index is returned relative to the start of the range.
§Example
let strings = vec!["a", "b", "f", "g", "m", "n", "q"];
let vec = VarZeroVec::<str>::from(&strings);
// Same behavior as binary_search when the range covers the whole slice:
assert_eq!(vec.binary_search_in_range("g", 0..7), Some(Ok(3)));
assert_eq!(vec.binary_search_in_range("h", 0..7), Some(Err(4)));
// Will not look outside of the range:
assert_eq!(vec.binary_search_in_range("g", 0..1), Some(Err(1)));
assert_eq!(vec.binary_search_in_range("g", 6..7), Some(Err(0)));
// Will return indices relative to the start of the range:
assert_eq!(vec.binary_search_in_range("g", 1..6), Some(Ok(2)));
assert_eq!(vec.binary_search_in_range("h", 1..6), Some(Err(3)));
// Will return `None` if the range is out of bounds:
assert_eq!(vec.binary_search_in_range("x", 100..200), None);
assert_eq!(vec.binary_search_in_range("x", 0..200), None);
Sourcepub fn binary_search_by(
&self,
predicate: impl FnMut(&T) -> Ordering,
) -> Result<usize, usize>
pub fn binary_search_by( &self, predicate: impl FnMut(&T) -> Ordering, ) -> Result<usize, usize>
Binary searches a sorted VarZeroVec<T>
for the given predicate. For more information, see
the standard library function binary_search_by
.
§Example
let strings = vec!["a", "b", "f", "g"];
let vec = VarZeroVec::<str>::from(&strings);
assert_eq!(vec.binary_search_by(|probe| probe.cmp("f")), Ok(2));
assert_eq!(vec.binary_search_by(|probe| probe.cmp("e")), Err(2));
Sourcepub fn binary_search_in_range_by(
&self,
predicate: impl FnMut(&T) -> Ordering,
range: Range<usize>,
) -> Option<Result<usize, usize>>
pub fn binary_search_in_range_by( &self, predicate: impl FnMut(&T) -> Ordering, range: Range<usize>, ) -> Option<Result<usize, usize>>
Binary searches a VarZeroVec<T>
for the given predicate within a certain sorted range.
If the range is out of bounds, returns None
. Otherwise, returns a Result
according
to the behavior of the standard library function binary_search
.
The index is returned relative to the start of the range.
§Example
let strings = vec!["a", "b", "f", "g", "m", "n", "q"];
let vec = VarZeroVec::<str>::from(&strings);
// Same behavior as binary_search when the range covers the whole slice:
assert_eq!(
vec.binary_search_in_range_by(|v| v.cmp("g"), 0..7),
Some(Ok(3))
);
assert_eq!(
vec.binary_search_in_range_by(|v| v.cmp("h"), 0..7),
Some(Err(4))
);
// Will not look outside of the range:
assert_eq!(
vec.binary_search_in_range_by(|v| v.cmp("g"), 0..1),
Some(Err(1))
);
assert_eq!(
vec.binary_search_in_range_by(|v| v.cmp("g"), 6..7),
Some(Err(0))
);
// Will return indices relative to the start of the range:
assert_eq!(
vec.binary_search_in_range_by(|v| v.cmp("g"), 1..6),
Some(Ok(2))
);
assert_eq!(
vec.binary_search_in_range_by(|v| v.cmp("h"), 1..6),
Some(Err(3))
);
// Will return `None` if the range is out of bounds:
assert_eq!(
vec.binary_search_in_range_by(|v| v.cmp("x"), 100..200),
None
);
assert_eq!(vec.binary_search_in_range_by(|v| v.cmp("x"), 0..200), None);
Trait Implementations§
Source§impl<T: ?Sized, F> Clone for VarZeroVecOwned<T, F>
impl<T: ?Sized, F> Clone for VarZeroVecOwned<T, F>
Source§impl<T, F: VarZeroVecFormat> Debug for VarZeroVecOwned<T, F>
impl<T, F: VarZeroVecFormat> Debug for VarZeroVecOwned<T, F>
Source§impl<T: VarULE + ?Sized, F: VarZeroVecFormat> Deref for VarZeroVecOwned<T, F>
impl<T: VarULE + ?Sized, F: VarZeroVecFormat> Deref for VarZeroVecOwned<T, F>
Source§type Target = VarZeroSlice<T, F>
type Target = VarZeroSlice<T, F>
Source§fn deref(&self) -> &VarZeroSlice<T, F>
fn deref(&self) -> &VarZeroSlice<T, F>
Source§impl<'a, T: ?Sized + VarULE, F: VarZeroVecFormat> From<&'a VarZeroSlice<T, F>> for VarZeroVecOwned<T, F>
impl<'a, T: ?Sized + VarULE, F: VarZeroVecFormat> From<&'a VarZeroSlice<T, F>> for VarZeroVecOwned<T, F>
Source§fn from(other: &'a VarZeroSlice<T, F>) -> Self
fn from(other: &'a VarZeroSlice<T, F>) -> Self
Source§impl<'a, T: ?Sized + VarULE, F: VarZeroVecFormat> From<VarZeroVec<'a, T, F>> for VarZeroVecOwned<T, F>
impl<'a, T: ?Sized + VarULE, F: VarZeroVecFormat> From<VarZeroVec<'a, T, F>> for VarZeroVecOwned<T, F>
Source§fn from(other: VarZeroVec<'a, T, F>) -> Self
fn from(other: VarZeroVec<'a, T, F>) -> Self
Source§impl<'a, T: ?Sized, F> From<VarZeroVecOwned<T, F>> for VarZeroVec<'a, T, F>
impl<'a, T: ?Sized, F> From<VarZeroVecOwned<T, F>> for VarZeroVec<'a, T, F>
Source§fn from(other: VarZeroVecOwned<T, F>) -> Self
fn from(other: VarZeroVecOwned<T, F>) -> Self
Source§impl<T, A, F> PartialEq<&[A]> for VarZeroVecOwned<T, F>
impl<T, A, F> PartialEq<&[A]> for VarZeroVecOwned<T, F>
Auto Trait Implementations§
impl<T, F> Freeze for VarZeroVecOwned<T, F>where
T: ?Sized,
impl<T, F> RefUnwindSafe for VarZeroVecOwned<T, F>
impl<T, F> Send for VarZeroVecOwned<T, F>
impl<T, F> Sync for VarZeroVecOwned<T, F>
impl<T, F> Unpin for VarZeroVecOwned<T, F>
impl<T, F> UnwindSafe for VarZeroVecOwned<T, F>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)