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 unsafe fn get_unchecked(&self, index: usize) -> &[u8] ⓘ
pub unsafe fn get_unchecked(&self, index: usize) -> &[u8] ⓘ
Returns a reference to the bytes at the given index without bounds checking.
§Safety
Caller must ensure index < self.len().
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 data(&self) -> &[u8] ⓘ
pub fn data(&self) -> &[u8] ⓘ
Returns a reference to the underlying data buffer.
§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();
assert_eq!(bytes.data(), b"hello world");Sourcepub fn parent(&self) -> &[u8] ⓘ
pub fn parent(&self) -> &[u8] ⓘ
Returns a reference to the parent byte buffer that all slices reference.
This is an alias for data() that provides a consistent API across all Cows types.
§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();
assert_eq!(bytes.parent(), b"hello 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"[..]]);