Struct vectorscan::sources::VectoredByteSlices
source · pub struct VectoredByteSlices<'string, 'slice>(/* private fields */);
vectored
only.Expand description
This struct wraps non-contiguous slices of string data to pass to the
scan_sync_vectored()
search
method, which produces match results of type
VectoredMatch
pointing to a subset of the original data.
This is currently implemented as
a #[repr(transparent)]
wrapper over &'slice [ByteSlice<'string>]
.
Implementations§
source§impl<'string, 'slice> VectoredByteSlices<'string, 'slice>
impl<'string, 'slice> VectoredByteSlices<'string, 'slice>
Byte-Oriented Interface
Because vectorscan only partially supports vectored string inputs, this
library does not attempt to provide a UTF8-encoded str
interface for vectored strings as with ByteSlice
.
However, From
implementations are still provided to convert from
references to arrays and slices:
use vectorscan::sources::VectoredByteSlices;
let b1 = b"asdf";
let b2 = b"bbbb";
let bb = [b1.into(), b2.into()];
let bs = VectoredByteSlices::from_slices(&bb);
let bb2 = [b1.as_ref(), b2.as_ref()];
let bs2: VectoredByteSlices = bb2.as_ref().into();
assert_eq!(bs, bs2);
sourcepub const fn from_slices(data: &'slice [ByteSlice<'string>]) -> Self
pub const fn from_slices(data: &'slice [ByteSlice<'string>]) -> Self
Wrap a slice of byte slices so they can be scanned in vectored mode.
Like ByteSlice::from_slice()
, this method is const
so it can be
used in const
values and static
initializers.
sourcepub fn length_sum(&self) -> usize
pub fn length_sum(&self) -> usize
Return the sum of all lengths of all slices.
source§impl<'string, 'slice> VectoredByteSlices<'string, 'slice>
impl<'string, 'slice> VectoredByteSlices<'string, 'slice>
Ownership and Indexing
Keeping track of a subset of vectored strings
requires some more work than for ByteSlice
, since a subset of vectored
data may start or stop in the middle of a particular slice. As a result,
Self::index_range()
cannot simply return Self
and return a reference
to itself without allocating new memory the way
ByteSlice::index_range()
can.
However, it is possible to avoid dynamic memory allocation when
extracting subsets of vectored data; instead, Self::index_range()
returns VectoredSubset
, which tracks offsets within the vectored
string data without additional allocations.
sourcepub fn index_range(
&self,
range: Range<usize>
) -> Option<VectoredSubset<'string, 'slice>>
pub fn index_range( &self, range: Range<usize> ) -> Option<VectoredSubset<'string, 'slice>>
Return a subset of the input, or None
if the result would be out of
range:
use vectorscan::sources::VectoredByteSlices;
let b1 = "asdf";
let b2 = "ok";
let b3 = "bsdf";
let bb = [b1.into(), b2.into(), b3.into()];
let bs = VectoredByteSlices::from_slices(&bb);
let sub = bs.index_range(2..8).unwrap();
let collected: Vec<&str> = sub.iter_slices().map(|s| unsafe { s.as_str() }).collect();
assert_eq!(&collected, &["df", "ok", "bs"]);
This method is largely intended for internal use inside this library, but is exposed in the public API to make it clear how the match callback converts match offsets to substrings of the original input data.
sourcepub fn as_slices(&self) -> &'slice [ByteSlice<'string>]
pub fn as_slices(&self) -> &'slice [ByteSlice<'string>]
Iterate over all of the original vectored data.
This is the corollary to VectoredSubset::iter_slices()
and is mainly
intended to aid in debugging.
use vectorscan::sources::VectoredByteSlices;
let b1 = "asdf";
let b2 = "ok";
let b3 = "bbbb";
let bb = [b1.into(), b2.into(), b3.into()];
let bs = VectoredByteSlices::from_slices(&bb);
let collected: Vec<&str> = bs.as_slices().iter().map(|s| unsafe { s.as_str() }).collect();
assert_eq!(&collected, &["asdf", "ok", "bbbb"]);
Trait Implementations§
source§impl<'string, 'slice> Clone for VectoredByteSlices<'string, 'slice>
impl<'string, 'slice> Clone for VectoredByteSlices<'string, 'slice>
source§fn clone(&self) -> VectoredByteSlices<'string, 'slice>
fn clone(&self) -> VectoredByteSlices<'string, 'slice>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl<'string, 'slice> Debug for VectoredByteSlices<'string, 'slice>
impl<'string, 'slice> Debug for VectoredByteSlices<'string, 'slice>
source§impl<'string, 'slice> From<&'slice [&'string [u8]]> for VectoredByteSlices<'string, 'slice>
impl<'string, 'slice> From<&'slice [&'string [u8]]> for VectoredByteSlices<'string, 'slice>
source§impl<'string, 'slice, const N: usize> From<&'slice [&'string [u8]; N]> for VectoredByteSlices<'string, 'slice>
impl<'string, 'slice, const N: usize> From<&'slice [&'string [u8]; N]> for VectoredByteSlices<'string, 'slice>
source§impl<'string, 'slice> From<&'slice [ByteSlice<'string>]> for VectoredByteSlices<'string, 'slice>
impl<'string, 'slice> From<&'slice [ByteSlice<'string>]> for VectoredByteSlices<'string, 'slice>
source§impl<'string, 'slice, const N: usize> From<&'slice [ByteSlice<'string>; N]> for VectoredByteSlices<'string, 'slice>
impl<'string, 'slice, const N: usize> From<&'slice [ByteSlice<'string>; N]> for VectoredByteSlices<'string, 'slice>
source§impl<'string, 'slice> Hash for VectoredByteSlices<'string, 'slice>
impl<'string, 'slice> Hash for VectoredByteSlices<'string, 'slice>
source§impl<'string, 'slice> Ord for VectoredByteSlices<'string, 'slice>
impl<'string, 'slice> Ord for VectoredByteSlices<'string, 'slice>
source§fn cmp(&self, other: &VectoredByteSlices<'string, 'slice>) -> Ordering
fn cmp(&self, other: &VectoredByteSlices<'string, 'slice>) -> Ordering
1.21.0 · source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
source§impl<'string, 'slice> PartialEq for VectoredByteSlices<'string, 'slice>
impl<'string, 'slice> PartialEq for VectoredByteSlices<'string, 'slice>
source§fn eq(&self, other: &VectoredByteSlices<'string, 'slice>) -> bool
fn eq(&self, other: &VectoredByteSlices<'string, 'slice>) -> bool
self
and other
values to be equal, and is used
by ==
.source§impl<'string, 'slice> PartialOrd for VectoredByteSlices<'string, 'slice>
impl<'string, 'slice> PartialOrd for VectoredByteSlices<'string, 'slice>
source§fn partial_cmp(
&self,
other: &VectoredByteSlices<'string, 'slice>
) -> Option<Ordering>
fn partial_cmp( &self, other: &VectoredByteSlices<'string, 'slice> ) -> Option<Ordering>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moreimpl<'string, 'slice> Copy for VectoredByteSlices<'string, 'slice>
impl<'string, 'slice> Eq for VectoredByteSlices<'string, 'slice>
impl<'string, 'slice> StructuralEq for VectoredByteSlices<'string, 'slice>
impl<'string, 'slice> StructuralPartialEq for VectoredByteSlices<'string, 'slice>
Auto Trait Implementations§
impl<'string, 'slice> RefUnwindSafe for VectoredByteSlices<'string, 'slice>
impl<'string, 'slice> Send for VectoredByteSlices<'string, 'slice>
impl<'string, 'slice> Sync for VectoredByteSlices<'string, 'slice>
impl<'string, 'slice> Unpin for VectoredByteSlices<'string, 'slice>
impl<'string, 'slice> UnwindSafe for VectoredByteSlices<'string, 'slice>
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<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.