Struct tendril::Tendril [] [src]

#[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.

Methods

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

Important traits for Tendril<Bytes, A>
[src]

Create a new, empty Tendril in any format.

Important traits for Tendril<Bytes, A>
[src]

Create a new, empty Tendril with a specified capacity.

[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.

[src]

Get the length of the Tendril.

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

[src]

Is the backing buffer shared?

[src]

Is the backing buffer shared with this other Tendril?

[src]

Truncate to length 0 without discarding any owned storage.

[src]

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

Important traits for Tendril<Bytes, A>
[src]

View as uninterpreted bytes.

Important traits for Tendril<Bytes, A>
[src]

Convert into uninterpreted bytes.

[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.

Important traits for Tendril<Bytes, A>
[src]

View as a superset format, for free.

Important traits for Tendril<Bytes, A>
[src]

Convert into a superset format, for free.

[src]

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

[src]

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

[src]

View as another format, if the bytes of the Tendril are valid for that 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.

[src]

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

[src]

Push another Tendril onto the end of this one.

[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.

Important traits for Tendril<Bytes, A>
[src]

Slice this Tendril as a new Tendril.

Panics on bounds or validity check failure.

[src]

Try to drop n bytes from the front.

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

[src]

Drop n bytes from the front.

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

[src]

Drop n bytes from the back.

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

[src]

Drop n bytes from the back.

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

Important traits for Tendril<Bytes, A>
[src]

View as another format, without validating.

Important traits for Tendril<Bytes, A>
[src]

Convert into another format, without validating.

Important traits for Tendril<Bytes, A>
[src]

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

[src]

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

Important traits for Tendril<Bytes, A>
[src]

Slice this Tendril as a new Tendril.

Does not check validity or bounds!

[src]

Drop n bytes from the front.

Does not check validity or bounds!

[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]

Important traits for Tendril<Bytes, A>
[src]

Build a Tendril by copying a 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]

[src]

Remove and return the first character, if any.

[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.

[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]

[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]

[src]

Push a character onto the end.

Important traits for Tendril<Bytes, A>
[src]

Create a Tendril from a single character.

Important traits for Tendril<Bytes, A>
[src]

Helper for the format_tendril! macro.

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

[src]

Trait Implementations

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

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

Important traits for Tendril<Bytes, A>
[src]

Returns a copy of the value. Read more

1.0.0
[src]

Performs copy-assignment from source. Read more

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

[src]

Executes the destructor for this type. Read more

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

[src]

Extends a collection with the contents of an iterator. Read more

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

[src]

Creates a value from an iterator. Read more

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

[src]

Extends a collection with the contents of an iterator. Read more

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

[src]

Creates a value from an iterator. Read more

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

[src]

Extends a collection with the contents of an iterator. Read more

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

[src]

Creates a value from an iterator. Read more

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

[src]

Extends a collection with the contents of an iterator. Read more

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

[src]

Creates a value from an iterator. Read more

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

[src]

Extends a collection with the contents of an iterator. Read more

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

[src]

Creates a value from an iterator. Read more

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

[src]

Extends a collection with the contents of an iterator. Read more

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

[src]

Creates a value from an iterator. Read more

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

The resulting type after dereferencing.

[src]

Dereferences the value.

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

[src]

Mutably dereferences the value.

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

[src]

Immutably borrows from an owned value. Read more

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

[src]

This method tests for self and other values to be equal, and is used by ==. Read more

[src]

This method tests for !=.

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

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

[src]

This method returns an ordering between self and other values if one exists. Read more

1.0.0
[src]

This method tests less than (for self and other) and is used by the < operator. Read more

1.0.0
[src]

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

1.0.0
[src]

This method tests greater than (for self and other) and is used by the > operator. Read more

1.0.0
[src]

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

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

[src]

This method returns an Ordering between self and other. Read more

1.21.0
[src]

Compares and returns the maximum of two values. Read more

1.21.0
[src]

Compares and returns the minimum of two values. Read more

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

Important traits for Tendril<Bytes, A>
[src]

Returns the "default value" for a type. Read more

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

[src]

Formats the value using the given formatter. Read more

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

[src]

Feeds this value into the given [Hasher]. Read more

1.3.0
[src]

Feeds a slice of this type into the given [Hasher]. Read more

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

[src]

Performs the conversion.

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

Important traits for Tendril<Bytes, A>
[src]

Performs the conversion.

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

[src]

Write a buffer into this object, returning how many bytes were written. Read more

[src]

Attempts to write an entire buffer into this write. Read more

[src]

Flush this output stream, ensuring that all intermediately buffered contents reach their destination. Read more

1.0.0
[src]

Writes a formatted string into this writer, returning any error encountered. Read more

1.0.0
[src]

Creates a "by reference" adaptor for this instance of Write. Read more

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

[src]

Formats the value using the given formatter. Read more

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

The associated error which can be returned from parsing.

[src]

Parses a string s to return a value of this type. Read more

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

[src]

Writes a slice of bytes into this writer, returning whether the write succeeded. Read more

1.1.0
[src]

Writes a [char] into this writer, returning whether the write succeeded. Read more

1.0.0
[src]

Glue for usage of the [write!] macro with implementors of this trait. Read more

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

Important traits for Tendril<Bytes, A>
[src]

Performs the conversion.

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

Important traits for Tendril<Bytes, A>
[src]

Performs the conversion.

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

[src]

Performs the conversion.

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

[src]

Performs the conversion.

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

[src]

Performs the conversion.