pub struct BytesTape<Offset: OffsetType = i32, A: Allocator = Global> { /* private fields */ }Expand description
Binary bytes view over RawTape.
Implementations§
Source§impl<Offset: OffsetType, A: Allocator> BytesTape<Offset, A>
impl<Offset: OffsetType, A: Allocator> BytesTape<Offset, A>
Sourcepub fn new() -> BytesTape<Offset, Global>
pub fn new() -> BytesTape<Offset, Global>
Creates a new, empty BytesTape with the global allocator.
Sourcepub fn with_capacity(
data_capacity: usize,
items_capacity: usize,
) -> Result<BytesTape<Offset, Global>, StringTapeError>
pub fn with_capacity( data_capacity: usize, items_capacity: usize, ) -> Result<BytesTape<Offset, Global>, StringTapeError>
Creates a new BytesTape with pre-allocated capacity using the global allocator.
Sourcepub fn with_capacity_in(
data_capacity: usize,
items_capacity: usize,
allocator: A,
) -> Result<Self, StringTapeError>
pub fn with_capacity_in( data_capacity: usize, items_capacity: usize, allocator: A, ) -> Result<Self, StringTapeError>
Creates a new BytesTape with pre-allocated capacity and a custom allocator.
Sourcepub fn push(&mut self, bytes: &[u8]) -> Result<(), StringTapeError>
pub fn push(&mut self, bytes: &[u8]) -> Result<(), StringTapeError>
Adds bytes to the end of the tape.
Sourcepub fn get(&self, index: usize) -> Option<&[u8]>
pub fn get(&self, index: usize) -> Option<&[u8]>
Returns a reference to the bytes at the given index, or None if out of bounds.
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 data_capacity(&self) -> usize
pub fn data_capacity(&self) -> usize
Returns the number of bytes allocated for data.
Sourcepub fn offsets_capacity(&self) -> usize
pub fn offsets_capacity(&self) -> usize
Returns the number of offset slots allocated.
Sourcepub fn truncate(&mut self, len: usize)
pub fn truncate(&mut self, len: usize)
Shortens the tape, keeping the first len items and dropping the rest.
Sourcepub fn contains(&self, item: &[u8]) -> bool
pub fn contains(&self, item: &[u8]) -> bool
Returns true if the tape contains the given byte slice.
Sourcepub fn shrink_to_fit(&mut self) -> Result<(), StringTapeError>
pub fn shrink_to_fit(&mut self) -> Result<(), StringTapeError>
Shrinks allocated capacity to fit current data.
Sourcepub fn extend<I>(&mut self, iter: I) -> Result<(), StringTapeError>
pub fn extend<I>(&mut self, iter: I) -> Result<(), StringTapeError>
Extends the tape with the contents of an iterator of bytes.
Sourcepub fn as_raw_parts(&self) -> RawParts<Offset>
pub fn as_raw_parts(&self) -> RawParts<Offset>
Returns the raw parts of the tape for Apache Arrow compatibility.
Sourcepub fn data_slice(&self) -> &[u8] ⓘ
pub fn data_slice(&self) -> &[u8] ⓘ
Returns a slice view of the data buffer.
Sourcepub fn offsets_slice(&self) -> &[Offset]
pub fn offsets_slice(&self) -> &[Offset]
Returns a slice view of the offsets buffer.
Sourcepub fn view(&self) -> BytesTapeView<'_, Offset>
pub fn view(&self) -> BytesTapeView<'_, Offset>
Creates a view of the entire BytesTape.
Sourcepub fn iter(&self) -> BytesTapeIter<'_, Offset, A> ⓘ
pub fn iter(&self) -> BytesTapeIter<'_, Offset, A> ⓘ
Returns an iterator over the byte cows.
Sourcepub fn subview(
&self,
start: usize,
end: usize,
) -> Result<BytesTapeView<'_, Offset>, StringTapeError>
pub fn subview( &self, start: usize, end: usize, ) -> Result<BytesTapeView<'_, Offset>, StringTapeError>
Creates a subview of a continuous slice of this BytesTape.
Sourcepub fn as_reorderable<Length: LengthType>(
&self,
) -> Result<BytesCows<'_, Offset, Length>, StringTapeError>
pub fn as_reorderable<Length: LengthType>( &self, ) -> Result<BytesCows<'_, Offset, Length>, StringTapeError>
Creates a BytesCows view of the tape.
§Example
let mut tape = BytesTapeI32::new();
tape.push(&[1, 2, 3])?;
tape.push(&[4, 5, 6])?;
tape.push(&[7, 8, 9])?;
let cows: BytesCows<i32, u16> = tape.as_reorderable()?;
assert_eq!(cows.get(0), Some(&[1, 2, 3][..]));Sourcepub fn arrow_slices(&self) -> (&[u8], &[Offset])
pub fn arrow_slices(&self) -> (&[u8], &[Offset])
Returns data and offsets slices for zero-copy Arrow conversion.
Source§impl<Offset: OffsetType, A: Allocator> BytesTape<Offset, A>
impl<Offset: OffsetType, A: Allocator> BytesTape<Offset, A>
pub fn try_into_chars_tape( self, ) -> Result<CharsTape<Offset, A>, StringTapeError>
Trait Implementations§
Source§impl<'a, Offset: OffsetType, A: Allocator> Extend<&'a [u8]> for BytesTape<Offset, A>
impl<'a, Offset: OffsetType, A: Allocator> Extend<&'a [u8]> for BytesTape<Offset, A>
Source§fn extend<I: IntoIterator<Item = &'a [u8]>>(&mut self, iter: I)
fn extend<I: IntoIterator<Item = &'a [u8]>>(&mut self, iter: I)
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one)