pub struct Builder<'a, const N: usize> { /* private fields */ }
Expand description
A struct to concatenate TokenString
s 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 TokenString
s and two 8 byte
fields, so (N + 2) * 8 bytes, (N + 2) * 64 bits.
Implementations§
Source§impl<'a, const N: usize> Builder<'a, N>
impl<'a, const N: usize> Builder<'a, N>
pub fn iter(&'a self) -> BuilderIter<'a, N> ⓘ
Sourcepub const fn new(s: &'a TokenString) -> Self
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.
Sourcepub const fn concat_unchecked(&mut self, s: &'a TokenString) -> &mut Self
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
.
Sourcepub const fn concat_checked(
&mut self,
s: &'a TokenString,
) -> Result<&mut Self, TkStrError>
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.
Sourcepub fn collect_checked(self) -> Result<TokenString, TkStrError>
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
.
Sourcepub fn collect_unchecked(self) -> TokenString
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.