Trait bytes::str::ByteStr
[−]
[src]
pub trait ByteStr: Clone + Sized + Send + Sync + Any + ToBytes + Index<usize, Output = u8> + 'static { type Buf: Buf + 'static; fn buf(&self) -> Self::Buf; fn concat<B: ByteStr + 'static>(&self, other: &B) -> Bytes; fn len(&self) -> usize; fn slice(&self, begin: usize, end: usize) -> Bytes; fn is_empty(&self) -> bool { ... } fn slice_from(&self, begin: usize) -> Bytes { ... } fn slice_to(&self, end: usize) -> Bytes { ... } fn split_at(&self, mid: usize) -> (Bytes, Bytes) { ... } }
An immutable sequence of bytes. Operations will not mutate the original value. Since only immutable access is permitted, operations do not require copying (though, sometimes copying will happen as an optimization).
Associated Types
Required Methods
fn buf(&self) -> Self::Buf
Returns a read-only Buf
for accessing the byte contents of the
ByteStr
.
fn concat<B: ByteStr + 'static>(&self, other: &B) -> Bytes
Returns a new Bytes
value representing the concatenation of self
with the given Bytes
.
fn len(&self) -> usize
Returns the number of bytes in the ByteStr
fn slice(&self, begin: usize, end: usize) -> Bytes
Returns a new ByteStr value containing the byte range between begin
(inclusive) and end
(exclusive)
Provided Methods
fn is_empty(&self) -> bool
Returns true if the length of the ByteStr
is 0
fn slice_from(&self, begin: usize) -> Bytes
Returns a new ByteStr value containing the byte range starting from
begin
(inclusive) to the end of the byte str.
Equivalent to bytes.slice(begin, bytes.len())
fn slice_to(&self, end: usize) -> Bytes
Returns a new ByteStr value containing the byte range from the start up
to end
(exclusive).
Equivalent to bytes.slice(0, end)
fn split_at(&self, mid: usize) -> (Bytes, Bytes)
Divides the value into two Bytes
at the given index.
The first will contain all bytes from [0, mid]
(excluding the index
mid
itself) and the second will contain all indices from [mid, len)
(excluding the index len
itself).
Panics if mid > len
.
Implementors
impl ByteStr for Bytes
impl ByteStr for Rope
impl ByteStr for SeqByteStr
impl ByteStr for SmallByteStr