[][src]Struct tendril::Tendril

#[repr(C)]pub struct Tendril<F, A = NonAtomic> where
    F: Format,
    A: Atomicity
{ /* fields omitted */ }

Compact string type for zero-copy parsing.

Tendrils have the semantics of owned strings, but are sometimes views into shared buffers. When you mutate a Tendril, an owned copy is made if necessary. Further mutations occur in-place until the string becomes shared, e.g. with clone() or subtendril().

Buffer sharing is accomplished through thread-local (non-atomic) reference counting, which has very low overhead. The Rust type system will prevent you at compile time from sending a Tendril between threads. We plan to relax this restriction in the future; see README.md.

Whereas String allocates in the heap for any non-empty string, Tendril can store small strings (up to 8 bytes) in-line, without a heap allocation. Tendril is also smaller than String on 64-bit platforms — 16 bytes versus 24.

The type parameter F specifies the format of the tendril, for example UTF-8 text or uninterpreted bytes. The parameter will be instantiated with one of the marker types from tendril::fmt. See the StrTendril and ByteTendril type aliases for two examples.

The type parameter A indicates the atomicity of the tendril; it is by default NonAtomic, but can be specified as Atomic to get a tendril which implements Send (viz. a thread-safe tendril).

The maximum length of a Tendril is 4 GB. The library will panic if you attempt to go over the limit.

Implementations

impl<F, A> Tendril<F, A> where
    F: Format,
    A: Atomicity
[src]

pub fn new() -> Tendril<F, A>

Notable traits for Tendril<Bytes, A>

impl<A> Write for Tendril<Bytes, A> where
    A: Atomicity
[src]

Create a new, empty Tendril in any format.

pub fn with_capacity(capacity: u32) -> Tendril<F, A>

Notable traits for Tendril<Bytes, A>

impl<A> Write for Tendril<Bytes, A> where
    A: Atomicity
[src]

Create a new, empty Tendril with a specified capacity.

pub fn reserve(&mut self, additional: u32)[src]

Reserve space for additional bytes.

This is only a suggestion. There are cases where Tendril will decline to allocate until the buffer is actually modified.

pub fn len32(&self) -> u32[src]

Get the length of the Tendril.

This is named not to conflict with len() on the underlying slice, if any.

pub fn is_shared(&self) -> bool[src]

Is the backing buffer shared?

pub fn is_shared_with(&self, other: &Tendril<F, A>) -> bool[src]

Is the backing buffer shared with this other Tendril?

pub fn clear(&mut self)[src]

Truncate to length 0 without discarding any owned storage.

pub fn try_from_byte_slice(x: &[u8]) -> Result<Tendril<F, A>, ()>[src]

Build a Tendril by copying a byte slice, if it conforms to the format.

pub fn as_bytes(&self) -> &Tendril<Bytes, A>

Notable traits for Tendril<Bytes, A>

impl<A> Write for Tendril<Bytes, A> where
    A: Atomicity
[src]

View as uninterpreted bytes.

pub fn into_bytes(self) -> Tendril<Bytes, A>

Notable traits for Tendril<Bytes, A>

impl<A> Write for Tendril<Bytes, A> where
    A: Atomicity
[src]

Convert into uninterpreted bytes.

pub fn into_send(self) -> SendTendril<F>[src]

Convert self into a type which is Send.

If the tendril is owned or inline, this is free, but if it's shared this will entail a copy of the contents.

pub fn as_superset<Super>(&self) -> &Tendril<Super, A>

Notable traits for Tendril<Bytes, A>

impl<A> Write for Tendril<Bytes, A> where
    A: Atomicity
where
    F: SubsetOf<Super>,
    Super: Format
[src]

View as a superset format, for free.

pub fn into_superset<Super>(self) -> Tendril<Super, A>

Notable traits for Tendril<Bytes, A>

impl<A> Write for Tendril<Bytes, A> where
    A: Atomicity
where
    F: SubsetOf<Super>,
    Super: Format
[src]

Convert into a superset format, for free.

pub fn try_as_subset<Sub>(&self) -> Result<&Tendril<Sub, A>, ()> where
    Sub: SubsetOf<F>, 
[src]

View as a subset format, if the Tendril conforms to that subset.

pub fn try_into_subset<Sub>(self) -> Result<Tendril<Sub, A>, Self> where
    Sub: SubsetOf<F>, 
[src]

Convert into a subset format, if the Tendril conforms to that subset.

pub fn try_reinterpret_view<Other>(&self) -> Result<&Tendril<Other, A>, ()> where
    Other: Format
[src]

View as another format, if the bytes of the Tendril are valid for that format.

pub fn try_reinterpret<Other>(self) -> Result<Tendril<Other, A>, Self> where
    Other: Format
[src]

Convert into another format, if the Tendril conforms to that format.

This only re-validates the existing bytes under the new format. It will not change the byte content of the tendril!

See the encode and decode methods for character encoding conversion.

pub fn try_push_bytes(&mut self, buf: &[u8]) -> Result<(), ()>[src]

Push some bytes onto the end of the Tendril, if they conform to the format.

pub fn push_tendril(&mut self, other: &Tendril<F, A>)[src]

Push another Tendril onto the end of this one.

pub fn try_subtendril(
    &self,
    offset: u32,
    length: u32
) -> Result<Tendril<F, A>, SubtendrilError>
[src]

Attempt to slice this Tendril as a new Tendril.

This will share the buffer when possible. Mutating a shared buffer will copy the contents.

The offset and length are in bytes. The function will return Err if these are out of bounds, or if the resulting slice does not conform to the format.

pub fn subtendril(&self, offset: u32, length: u32) -> Tendril<F, A>

Notable traits for Tendril<Bytes, A>

impl<A> Write for Tendril<Bytes, A> where
    A: Atomicity
[src]

Slice this Tendril as a new Tendril.

Panics on bounds or validity check failure.

pub fn try_pop_front(&mut self, n: u32) -> Result<(), SubtendrilError>[src]

Try to drop n bytes from the front.

Returns Err if the bytes are not available, or the suffix fails validation.

pub fn pop_front(&mut self, n: u32)[src]

Drop n bytes from the front.

Panics if the bytes are not available, or the suffix fails validation.

pub fn try_pop_back(&mut self, n: u32) -> Result<(), SubtendrilError>[src]

Drop n bytes from the back.

Returns Err if the bytes are not available, or the prefix fails validation.

pub fn pop_back(&mut self, n: u32)[src]

Drop n bytes from the back.

Panics if the bytes are not available, or the prefix fails validation.

pub unsafe fn reinterpret_view_without_validating<Other>(
    &self
) -> &Tendril<Other, A>

Notable traits for Tendril<Bytes, A>

impl<A> Write for Tendril<Bytes, A> where
    A: Atomicity
where
    Other: Format
[src]

View as another format, without validating.

pub unsafe fn reinterpret_without_validating<Other>(self) -> Tendril<Other, A>

Notable traits for Tendril<Bytes, A>

impl<A> Write for Tendril<Bytes, A> where
    A: Atomicity
where
    Other: Format
[src]

Convert into another format, without validating.

pub unsafe fn from_byte_slice_without_validating(x: &[u8]) -> Tendril<F, A>

Notable traits for Tendril<Bytes, A>

impl<A> Write for Tendril<Bytes, A> where
    A: Atomicity
[src]

Build a Tendril by copying a byte slice, without validating.

pub unsafe fn push_bytes_without_validating(&mut self, buf: &[u8])[src]

Push some bytes onto the end of the Tendril, without validating.

pub unsafe fn unsafe_subtendril(
    &self,
    offset: u32,
    length: u32
) -> Tendril<F, A>

Notable traits for Tendril<Bytes, A>

impl<A> Write for Tendril<Bytes, A> where
    A: Atomicity
[src]

Slice this Tendril as a new Tendril.

Does not check validity or bounds!

pub unsafe fn unsafe_pop_front(&mut self, n: u32)[src]

Drop n bytes from the front.

Does not check validity or bounds!

pub unsafe fn unsafe_pop_back(&mut self, n: u32)[src]

Drop n bytes from the back.

Does not check validity or bounds!

impl<F, A> Tendril<F, A> where
    F: SliceFormat,
    A: Atomicity
[src]

pub fn from_slice(x: &F::Slice) -> Tendril<F, A>

Notable traits for Tendril<Bytes, A>

impl<A> Write for Tendril<Bytes, A> where
    A: Atomicity
[src]

Build a Tendril by copying a slice.

pub fn push_slice(&mut self, x: &F::Slice)[src]

Push a slice onto the end of the Tendril.

impl<F, A> Tendril<F, A> where
    F: for<'a> CharFormat<'a>,
    A: Atomicity
[src]

pub fn pop_front_char<'a>(&'a mut self) -> Option<char>[src]

Remove and return the first character, if any.

pub fn pop_front_char_run<'a, C, R>(
    &'a mut self,
    classify: C
) -> Option<(Tendril<F, A>, R)> where
    C: FnMut(char) -> R,
    R: PartialEq
[src]

Remove and return a run of characters at the front of the Tendril which are classified the same according to the function classify.

Returns None on an empty string.

pub fn try_push_char(&mut self, c: char) -> Result<(), ()>[src]

Push a character, if it can be represented in this format.

impl<F, A> Tendril<F, A> where
    A: Atomicity,
    F: SliceFormat<Slice = [u8]>, 
[src]

pub unsafe fn push_uninitialized(&mut self, n: u32)[src]

Push "uninitialized bytes" onto the end.

Really, this grows the tendril without writing anything to the new area. It's only defined for byte tendrils because it's only useful if you plan to then mutate the buffer.

impl<A> Tendril<UTF8, A> where
    A: Atomicity
[src]

pub fn push_char(&mut self, c: char)[src]

Push a character onto the end.

pub fn from_char(c: char) -> Tendril<UTF8, A>

Notable traits for Tendril<Bytes, A>

impl<A> Write for Tendril<Bytes, A> where
    A: Atomicity
[src]

Create a Tendril from a single character.

pub fn format(args: Arguments<'_>) -> Tendril<UTF8, A>

Notable traits for Tendril<Bytes, A>

impl<A> Write for Tendril<Bytes, A> where
    A: Atomicity
[src]

Helper for the format_tendril! macro.

impl<A> Tendril<Bytes, A> where
    A: Atomicity
[src]

pub fn decode_utf8_lossy<F>(self, push_utf8: F) -> Option<IncompleteUtf8> where
    F: FnMut(Tendril<UTF8, A>), 
[src]

Trait Implementations

impl<F, A> AsRef<<F as SliceFormat>::Slice> for Tendril<F, A> where
    F: SliceFormat,
    A: Atomicity
[src]

impl<F, A> Borrow<[u8]> for Tendril<F, A> where
    F: SliceFormat,
    A: Atomicity
[src]

impl<F, A> Clone for Tendril<F, A> where
    F: Format,
    A: Atomicity
[src]

impl<F, A> Debug for Tendril<F, A> where
    F: SliceFormat + Default + Debug,
    <F as SliceFormat>::Slice: Debug,
    A: Atomicity
[src]

impl<F, A> Default for Tendril<F, A> where
    F: Format,
    A: Atomicity
[src]

impl<F, A> Deref for Tendril<F, A> where
    F: SliceFormat,
    A: Atomicity
[src]

type Target = F::Slice

The resulting type after dereferencing.

impl<F, A> DerefMut for Tendril<F, A> where
    F: SliceFormat,
    A: Atomicity
[src]

impl<A> Display for Tendril<UTF8, A> where
    A: Atomicity
[src]

impl<F, A> Drop for Tendril<F, A> where
    F: Format,
    A: Atomicity
[src]

impl<F, A> Eq for Tendril<F, A> where
    F: Format,
    A: Atomicity
[src]

impl<'a, A> Extend<&'a [u8]> for Tendril<Bytes, A> where
    A: Atomicity
[src]

impl<'a, F, A> Extend<&'a Tendril<F, A>> for Tendril<F, A> where
    F: Format + 'a,
    A: Atomicity
[src]

impl<'a, A> Extend<&'a str> for Tendril<UTF8, A> where
    A: Atomicity
[src]

impl<'a, A> Extend<&'a u8> for Tendril<Bytes, A> where
    A: Atomicity
[src]

impl<A> Extend<char> for Tendril<UTF8, A> where
    A: Atomicity
[src]

impl<A> Extend<u8> for Tendril<Bytes, A> where
    A: Atomicity
[src]

impl<'a, F, A> From<&'a <F as SliceFormat>::Slice> for Tendril<F, A> where
    F: SliceFormat,
    A: Atomicity
[src]

impl<'a, A> From<&'a Tendril<UTF8, A>> for String where
    A: Atomicity
[src]

impl<F, A> From<SendTendril<F>> for Tendril<F, A> where
    F: Format,
    A: Atomicity
[src]

impl<A> From<String> for Tendril<UTF8, A> where
    A: Atomicity
[src]

impl<F, A> From<Tendril<F, A>> for SendTendril<F> where
    F: Format,
    A: Atomicity
[src]

impl<A> From<Tendril<UTF8, A>> for String where
    A: Atomicity
[src]

impl<'a, A> FromIterator<&'a [u8]> for Tendril<Bytes, A> where
    A: Atomicity
[src]

impl<'a, F, A> FromIterator<&'a Tendril<F, A>> for Tendril<F, A> where
    F: Format + 'a,
    A: Atomicity
[src]

impl<'a, A> FromIterator<&'a str> for Tendril<UTF8, A> where
    A: Atomicity
[src]

impl<'a, A> FromIterator<&'a u8> for Tendril<Bytes, A> where
    A: Atomicity
[src]

impl<A> FromIterator<char> for Tendril<UTF8, A> where
    A: Atomicity
[src]

impl<A> FromIterator<u8> for Tendril<Bytes, A> where
    A: Atomicity
[src]

impl<A> FromStr for Tendril<UTF8, A> where
    A: Atomicity
[src]

type Err = ()

The associated error which can be returned from parsing.

impl<F, A> Hash for Tendril<F, A> where
    F: Format,
    A: Atomicity
[src]

impl<F, A> Ord for Tendril<F, A> where
    F: SliceFormat,
    <F as SliceFormat>::Slice: Ord,
    A: Atomicity
[src]

impl<F, A> PartialEq<Tendril<F, A>> for Tendril<F, A> where
    F: Format,
    A: Atomicity
[src]

impl<F, A> PartialOrd<Tendril<F, A>> for Tendril<F, A> where
    F: SliceFormat,
    <F as SliceFormat>::Slice: PartialOrd,
    A: Atomicity
[src]

impl<F, A> Send for Tendril<F, A> where
    F: Format,
    A: Atomicity + Sync
[src]

impl<A> Write for Tendril<UTF8, A> where
    A: Atomicity
[src]

impl<A> Write for Tendril<Bytes, A> where
    A: Atomicity
[src]

Auto Trait Implementations

impl<F, A = NonAtomic> !RefUnwindSafe for Tendril<F, A>[src]

impl<F, A = NonAtomic> !Sync for Tendril<F, A>[src]

impl<F, A> Unpin for Tendril<F, A> where
    A: Unpin
[src]

impl<F, A> UnwindSafe for Tendril<F, A> where
    A: UnwindSafe,
    F: RefUnwindSafe
[src]

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.