Struct Builder

Source
pub struct Builder<'a, const N: usize> { /* private fields */ }
Expand description

A struct to concatenate TokenStrings without allocating unnecessary memory on the heap.

The const generic parameter N should be set to the number of strings to concatenate. See the crate::concat! macro for a more comfortable way to use a Builder.

Memory:

Uses a static array of N pointers to TokenStrings and two 8 byte fields, so (N + 2) * 8 bytes, (N + 2) * 64 bits.

Implementations§

Source§

impl<'a, const N: usize> Builder<'a, N>

Source

pub fn iter(&'a self) -> BuilderIter<'a, N>

Source

pub const fn new(s: &'a TokenString) -> Self

Create a new Builder from the given TokenString.

Use this to concatenate the given string with other strings.

§Panics

Panics, if the number of strings to concatenate is set to 0.

Source

pub const fn concat_unchecked(&mut self, s: &'a TokenString) -> &mut Self

Concatenate the given string at the end of the builder.

See also Builder::concat_checked for the version that checks for errors, or the trait method Concat::concat.

§Panics

Panics, if the number of concatenated strings is bigger than the size reserved by the constant generic N of Builder.

Source

pub const fn concat_checked( &mut self, s: &'a TokenString, ) -> Result<&mut Self, TkStrError>

Concatenate another string to the end of the builder.

See also Builder::concat_unchecked for the version that does not check for errors, or the trait method concat.

§Errors

This function will return TkStrError::TooBig if the concatenated string is greater than MAX_LENGTH. If more than N, the const generic value of the Builder, strings are being concatenated, TkStrError::TooMany is returned.

Source

pub fn collect_checked(self) -> Result<TokenString, TkStrError>

Collect all strings passed to this Builder.

§Errors

Returns TkStrError::TooBig if the sum of all string lengths is greater than MAX_LENGTH.

Source

pub fn collect_unchecked(self) -> TokenString

Collect all strings passed to this Builder.

§Panics

If the concatenated string would be greater than MAX_LENGTH, this panics.

Trait Implementations§

Source§

impl<'a, const N: usize> Clone for Builder<'a, N>

Source§

fn clone(&self) -> Builder<'a, N>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a, const N: usize> Collect for &'a mut Builder<'a, N>

Source§

fn collect(self) -> Result<TokenString, TkStrError>

Actually concatenate all strings given to the Builder. Read more
Source§

impl<'a, const N: usize> Concat<&'a TokenString> for &'a mut Builder<'a, N>

Source§

type Output = &'a mut Builder<'a, N>

Source§

fn concat(self, s: &'a TokenString) -> Result<Self::Output, TkStrError>

Concatenate another string to the end of the builder. Read more
Source§

impl<'a, const N: usize> Debug for Builder<'a, N>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<const N: usize> Display for Builder<'_, N>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'a, const N: usize> IntoIterator for &'a Builder<'a, N>

Source§

type IntoIter = BuilderIter<'a, N>

Which kind of iterator are we turning this into?
Source§

type Item = &'a TokenString

The type of the elements being iterated over.
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<'a, const N: usize> Copy for Builder<'a, N>

Auto Trait Implementations§

§

impl<'a, const N: usize> Freeze for Builder<'a, N>

§

impl<'a, const N: usize> RefUnwindSafe for Builder<'a, N>

§

impl<'a, const N: usize> !Send for Builder<'a, N>

§

impl<'a, const N: usize> !Sync for Builder<'a, N>

§

impl<'a, const N: usize> Unpin for Builder<'a, N>

§

impl<'a, const N: usize> UnwindSafe for Builder<'a, N>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.