pub enum BytesCowsAuto<'a> {
U32U8(BytesCows<'a, u32, u8>),
U32U16(BytesCows<'a, u32, u16>),
U32U32(BytesCows<'a, u32, u32>),
U64U8(BytesCows<'a, u64, u8>),
U64U16(BytesCows<'a, u64, u16>),
U64U32(BytesCows<'a, u64, u32>),
}Expand description
Automatically selects the most memory-efficient BytesCows type based on data size.
Variants§
U32U8(BytesCows<'a, u32, u8>)
U32U16(BytesCows<'a, u32, u16>)
U32U32(BytesCows<'a, u32, u32>)
U64U8(BytesCows<'a, u64, u8>)
U64U16(BytesCows<'a, u64, u16>)
U64U32(BytesCows<'a, u64, u32>)
Implementations§
Source§impl<'a> BytesCowsAuto<'a>
impl<'a> BytesCowsAuto<'a>
Sourcepub fn from_iter_and_data<I>(
iter: I,
data: Cow<'a, [u8]>,
) -> Result<Self, StringTapeError>
pub fn from_iter_and_data<I>( iter: I, data: Cow<'a, [u8]>, ) -> Result<Self, StringTapeError>
Creates BytesCowsAuto from iterator of byte cows. Auto-selects offset and length types based on data size and max slice length.
pub fn len(&self) -> usize
pub fn is_empty(&self) -> bool
pub fn get(&self, index: usize) -> Option<&[u8]>
Sourcepub fn as_chars(&self) -> Result<CharsCowsAuto<'_>, StringTapeError>
pub fn as_chars(&self) -> Result<CharsCowsAuto<'_>, StringTapeError>
Returns a zero-copy view of this BytesCowsAuto as a CharsCowsAuto if all slices are valid UTF-8.
This validates that all byte slices contain valid UTF-8, then reinterprets the collection as strings without copying or moving any data.
§Errors
Returns StringTapeError::Utf8Error if any slice contains invalid UTF-8.
§Examples
use stringtape::BytesCowsAuto;
use std::borrow::Cow;
let data = b"hello world";
let bytes = BytesCowsAuto::from_iter_and_data(
data.split(|&b| b == b' '),
Cow::Borrowed(&data[..])
).unwrap();
let chars = bytes.as_chars().unwrap();
assert_eq!(chars.get(0), Some("hello"));
assert_eq!(chars.get(1), Some("world"));Sourcepub fn iter(&self) -> BytesCowsAutoIter<'_> ⓘ
pub fn iter(&self) -> BytesCowsAutoIter<'_> ⓘ
Returns an iterator over the byte cows.
§Examples
use stringtape::BytesCowsAuto;
use std::borrow::Cow;
let data = b"hello world foo";
let bytes = BytesCowsAuto::from_iter_and_data(
data.split(|&b| b == b' '),
Cow::Borrowed(&data[..])
).unwrap();
let slices: Vec<&[u8]> = bytes.iter().collect();
assert_eq!(slices, vec![&b"hello"[..], &b"world"[..], &b"foo"[..]]);Trait Implementations§
Source§impl<'a> IntoIterator for &'a BytesCowsAuto<'a>
impl<'a> IntoIterator for &'a BytesCowsAuto<'a>
Auto Trait Implementations§
impl<'a> Freeze for BytesCowsAuto<'a>
impl<'a> RefUnwindSafe for BytesCowsAuto<'a>
impl<'a> Send for BytesCowsAuto<'a>
impl<'a> Sync for BytesCowsAuto<'a>
impl<'a> Unpin for BytesCowsAuto<'a>
impl<'a> UnwindSafe for BytesCowsAuto<'a>
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
Mutably borrows from an owned value. Read more