Struct xml5ever::tendril::Tendril [−]
#[repr(C)]pub struct Tendril<F, A = NonAtomic> where
F: Format,
A: Atomicity, { /* fields omitted */ }
Expand description
Compact string type for zero-copy parsing.
Tendril
s 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
Create a new, empty Tendril
in any format.
Create a new, empty Tendril
with a specified capacity.
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.
Get the length of the Tendril
.
This is named not to conflict with len()
on the underlying
slice, if any.
Is the backing buffer shared?
Is the backing buffer shared with this other Tendril
?
pub fn clear(&mut self)
pub fn clear(&mut self)
Truncate to length 0 without discarding any owned storage.
Build a Tendril
by copying a byte slice, if it conforms to the format.
View as uninterpreted bytes.
Convert into uninterpreted bytes.
pub fn into_send(self) -> SendTendril<F>
pub fn into_send(self) -> SendTendril<F>
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.
View as a superset format, for free.
Convert into a superset format, for free.
pub fn try_as_subset<Sub>(&self) -> Result<&Tendril<Sub, A>, ()> where
Sub: SubsetOf<F>,
pub fn try_as_subset<Sub>(&self) -> Result<&Tendril<Sub, A>, ()> where
Sub: SubsetOf<F>,
View as a subset format, if the Tendril
conforms to that subset.
pub fn try_into_subset<Sub>(self) -> Result<Tendril<Sub, A>, Tendril<F, A>> where
Sub: SubsetOf<F>,
pub fn try_into_subset<Sub>(self) -> Result<Tendril<Sub, A>, Tendril<F, A>> where
Sub: SubsetOf<F>,
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,
pub fn try_reinterpret_view<Other>(&self) -> Result<&Tendril<Other, A>, ()> where
Other: Format,
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>, Tendril<F, A>> where
Other: Format,
pub fn try_reinterpret<Other>(self) -> Result<Tendril<Other, A>, Tendril<F, A>> where
Other: Format,
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.
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>)
pub fn push_tendril(&mut self, other: &Tendril<F, A>)
Push another Tendril
onto the end of this one.
pub fn try_subtendril(
&self,
offset: u32,
length: u32
) -> Result<Tendril<F, A>, SubtendrilError>
pub fn try_subtendril(
&self,
offset: u32,
length: u32
) -> Result<Tendril<F, A>, SubtendrilError>
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.
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>
pub fn try_pop_front(&mut self, n: u32) -> Result<(), SubtendrilError>
Try to drop n
bytes from the front.
Returns Err
if the bytes are not available, or the suffix fails
validation.
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>
pub fn try_pop_back(&mut self, n: u32) -> Result<(), SubtendrilError>
Drop n
bytes from the back.
Returns Err
if the bytes are not available, or the prefix fails
validation.
Drop n
bytes from the back.
Panics if the bytes are not available, or the prefix fails validation.
View as another format, without validating.
Convert into another format, without validating.
Build a Tendril
by copying a byte slice, without validating.
pub unsafe fn push_bytes_without_validating(&mut self, buf: &[u8])
pub unsafe fn push_bytes_without_validating(&mut self, buf: &[u8])
Push some bytes onto the end of the Tendril
, without validating.
Slice this Tendril
as a new Tendril
.
Does not check validity or bounds!
pub unsafe fn unsafe_pop_front(&mut self, n: u32)
pub unsafe fn unsafe_pop_front(&mut self, n: u32)
Drop n
bytes from the front.
Does not check validity or bounds!
pub unsafe fn unsafe_pop_back(&mut self, n: u32)
pub unsafe fn unsafe_pop_back(&mut self, n: u32)
Drop n
bytes from the back.
Does not check validity or bounds!
impl<F, A> Tendril<F, A> where
F: SliceFormat,
A: Atomicity,
impl<F, A> Tendril<F, A> where
F: SliceFormat,
A: Atomicity,
pub fn from_slice(x: &<F as SliceFormat>::Slice) -> Tendril<F, A>ⓘ
pub fn from_slice(x: &<F as SliceFormat>::Slice) -> Tendril<F, A>ⓘ
Build a Tendril
by copying a slice.
pub fn push_slice(&mut self, x: &<F as SliceFormat>::Slice)
pub fn push_slice(&mut self, x: &<F as SliceFormat>::Slice)
Push a slice onto the end of the Tendril
.
impl<F, A> Tendril<F, A> where
F: for<'a> CharFormat<'a>,
A: Atomicity,
impl<F, A> Tendril<F, A> where
F: for<'a> CharFormat<'a>,
A: Atomicity,
pub fn pop_front_char(&'a mut self) -> Option<char>
pub fn pop_front_char(&'a mut self) -> Option<char>
Remove and return the first character, if any.
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<(), ()>
pub fn try_push_char(&mut self, c: char) -> Result<(), ()>
Push a character, if it can be represented in this format.
pub unsafe fn push_uninitialized(&mut self, n: u32)
pub unsafe fn push_uninitialized(&mut self, n: u32)
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.
Create a Tendril
from a single character.
pub fn decode_utf8_lossy<F>(self, push_utf8: F) -> Option<IncompleteUtf8> where
F: FnMut(Tendril<UTF8, A>),
Trait Implementations
impl<F, A> AsRef<<F as SliceFormat>::Slice> for Tendril<F, A> where
F: SliceFormat,
A: Atomicity,
impl<F, A> AsRef<<F as SliceFormat>::Slice> for Tendril<F, A> where
F: SliceFormat,
A: Atomicity,
pub fn as_ref(&self) -> &<F as SliceFormat>::Slice
pub fn as_ref(&self) -> &<F as SliceFormat>::Slice
Performs the conversion.
impl<F, A> Debug for Tendril<F, A> where
F: SliceFormat + Default + Debug,
A: Atomicity,
<F as SliceFormat>::Slice: Debug,
impl<F, A> Debug for Tendril<F, A> where
F: SliceFormat + Default + Debug,
A: Atomicity,
<F as SliceFormat>::Slice: Debug,
impl<F, A> Deref for Tendril<F, A> where
F: SliceFormat,
A: Atomicity,
impl<F, A> Deref for Tendril<F, A> where
F: SliceFormat,
A: Atomicity,
type Target = <F as SliceFormat>::Slice
type Target = <F as SliceFormat>::Slice
The resulting type after dereferencing.
pub fn deref(&self) -> &<F as SliceFormat>::Slice
pub fn deref(&self) -> &<F as SliceFormat>::Slice
Dereferences the value.
impl<F, A> DerefMut for Tendril<F, A> where
F: SliceFormat,
A: Atomicity,
impl<F, A> DerefMut for Tendril<F, A> where
F: SliceFormat,
A: Atomicity,
pub fn deref_mut(&mut self) -> &mut <F as SliceFormat>::Slice
pub fn deref_mut(&mut self) -> &mut <F as SliceFormat>::Slice
Mutably dereferences the value.
pub fn extend<I>(&mut self, iterable: I) where
I: IntoIterator<Item = &'a [u8]>,
pub fn extend<I>(&mut self, iterable: I) where
I: IntoIterator<Item = &'a [u8]>,
Extends a collection with the contents of an iterator. Read more
extend_one
)Extends a collection with exactly one element.
extend_one
)Reserves capacity in a collection for the given number of additional elements. Read more
pub fn extend<I>(&mut self, iterable: I) where
I: IntoIterator<Item = &'a Tendril<F, A>>,
pub fn extend<I>(&mut self, iterable: I) where
I: IntoIterator<Item = &'a Tendril<F, A>>,
Extends a collection with the contents of an iterator. Read more
extend_one
)Extends a collection with exactly one element.
extend_one
)Reserves capacity in a collection for the given number of additional elements. Read more
pub fn extend<I>(&mut self, iterable: I) where
I: IntoIterator<Item = &'a str>,
pub fn extend<I>(&mut self, iterable: I) where
I: IntoIterator<Item = &'a str>,
Extends a collection with the contents of an iterator. Read more
extend_one
)Extends a collection with exactly one element.
extend_one
)Reserves capacity in a collection for the given number of additional elements. Read more
pub fn extend<I>(&mut self, iterable: I) where
I: IntoIterator<Item = &'a u8>,
pub fn extend<I>(&mut self, iterable: I) where
I: IntoIterator<Item = &'a u8>,
Extends a collection with the contents of an iterator. Read more
extend_one
)Extends a collection with exactly one element.
extend_one
)Reserves capacity in a collection for the given number of additional elements. Read more
pub fn extend<I>(&mut self, iterable: I) where
I: IntoIterator<Item = char>,
pub fn extend<I>(&mut self, iterable: I) where
I: IntoIterator<Item = char>,
Extends a collection with the contents of an iterator. Read more
extend_one
)Extends a collection with exactly one element.
extend_one
)Reserves capacity in a collection for the given number of additional elements. Read more
pub fn extend<I>(&mut self, iterable: I) where
I: IntoIterator<Item = u8>,
pub fn extend<I>(&mut self, iterable: I) where
I: IntoIterator<Item = u8>,
Extends a collection with the contents of an iterator. Read more
extend_one
)Extends a collection with exactly one element.
extend_one
)Reserves capacity in a collection for the given number of additional elements. Read more
impl<'a, F, A> From<&'a <F as SliceFormat>::Slice> for Tendril<F, A> where
F: SliceFormat,
A: Atomicity,
impl<'a, F, A> From<&'a <F as SliceFormat>::Slice> for Tendril<F, A> where
F: SliceFormat,
A: Atomicity,
impl<F, A> From<SendTendril<F>> for Tendril<F, A> where
F: Format,
A: Atomicity,
impl<F, A> From<SendTendril<F>> for Tendril<F, A> where
F: Format,
A: Atomicity,
impl<F, A> From<Tendril<F, A>> for SendTendril<F> where
F: Format,
A: Atomicity,
impl<F, A> From<Tendril<F, A>> for SendTendril<F> where
F: Format,
A: Atomicity,
pub fn from(tendril: Tendril<F, A>) -> SendTendril<F>
pub fn from(tendril: Tendril<F, A>) -> SendTendril<F>
Performs the conversion.
impl<'a, F, A> FromIterator<&'a Tendril<F, A>> for Tendril<F, A> where
F: 'a + Format,
A: Atomicity,
impl<'a, F, A> FromIterator<&'a Tendril<F, A>> for Tendril<F, A> where
F: 'a + Format,
A: Atomicity,
impl<'a, A> FromIterator<&'a str> for Tendril<UTF8, A> where
A: Atomicity,
impl<'a, A> FromIterator<&'a str> for Tendril<UTF8, A> where
A: Atomicity,
impl<'a, A> FromIterator<&'a u8> for Tendril<Bytes, A> where
A: Atomicity,
impl<'a, A> FromIterator<&'a u8> for Tendril<Bytes, A> where
A: Atomicity,
impl<A> FromIterator<char> for Tendril<UTF8, A> where
A: Atomicity,
impl<A> FromIterator<char> for Tendril<UTF8, A> where
A: Atomicity,
impl<A> FromIterator<u8> for Tendril<Bytes, A> where
A: Atomicity,
impl<A> FromIterator<u8> for Tendril<Bytes, A> where
A: Atomicity,
impl<F, A> Ord for Tendril<F, A> where
F: SliceFormat,
A: Atomicity,
<F as SliceFormat>::Slice: Ord,
impl<F, A> Ord for Tendril<F, A> where
F: SliceFormat,
A: Atomicity,
<F as SliceFormat>::Slice: Ord,
impl<F, A> PartialOrd<Tendril<F, A>> for Tendril<F, A> where
F: SliceFormat,
A: Atomicity,
<F as SliceFormat>::Slice: PartialOrd<<F as SliceFormat>::Slice>,
impl<F, A> PartialOrd<Tendril<F, A>> for Tendril<F, A> where
F: SliceFormat,
A: Atomicity,
<F as SliceFormat>::Slice: PartialOrd<<F as SliceFormat>::Slice>,
pub fn partial_cmp(&self, other: &Tendril<F, A>) -> Option<Ordering>
pub fn partial_cmp(&self, other: &Tendril<F, A>) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
This method tests less than (for self
and other
) and is used by the <
operator. Read more
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
Writes a string slice into this writer, returning whether the write succeeded. Read more
Write a buffer into this writer, returning how many bytes were written. Read more
Attempts to write an entire buffer into this writer. Read more
Flush this output stream, ensuring that all intermediately buffered contents reach their destination. Read more
can_vector
)Determines if this Write
r has an efficient write_vectored
implementation. Read more
write_all_vectored
)Attempts to write multiple buffers into this writer. Read more
Writes a formatted string into this writer, returning any error encountered. Read more
Auto Trait Implementations
impl<F, A = NonAtomic> !RefUnwindSafe for Tendril<F, A>
impl<F, A> UnwindSafe for Tendril<F, A> where
A: UnwindSafe,
F: RefUnwindSafe,
Blanket Implementations
Mutably borrows from an owned value. Read more