pub enum KStringWriter {
Inline(StackString<{ KString::MAX_INLINE_LEN }>),
Owned(String),
}
Expand description
A writer that can append formatted text to either an inline StackString
or a heap-allocated String
.
The KStringWriter
starts writing into a stack-allocated StackString
for efficiency. If the capacity
of the inline storage is exceeded, it switches to using a heap-allocated String
. This allows for
efficient formatting without unnecessary allocations in cases where the formatted text fits within the
inline buffer.
§Examples
use lstring::{KString, KStringWriter};
use core::fmt::Write;
let mut writer = KStringWriter::default();
write!(writer, "Hello, {}!", "world").unwrap();
let s: KString = writer.into();
assert_eq!(s, "Hello, world!");
Variants§
Inline(StackString<{ KString::MAX_INLINE_LEN }>)
Owned(String)
Implementations§
Source§impl KStringWriter
impl KStringWriter
pub fn new() -> Self
Sourcepub fn reserve(&mut self, additional: usize)
pub fn reserve(&mut self, additional: usize)
Reserves additional capacity for the KStringWriter
.
If the writer is currently using an inline StackString
and the requested capacity exceeds
its maximum inline length, it will switch to a heap-allocated String
. This method ensures
that subsequent writes do not require reallocations if the specified capacity is available.
Trait Implementations§
Source§impl AsRef<str> for KStringWriter
impl AsRef<str> for KStringWriter
Source§impl Clone for KStringWriter
impl Clone for KStringWriter
Source§fn clone(&self) -> KStringWriter
fn clone(&self) -> KStringWriter
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreSource§impl Default for KStringWriter
impl Default for KStringWriter
Source§impl<'a, B: HeapStr> Extend<&'a KString<B>> for KStringWriter
impl<'a, B: HeapStr> Extend<&'a KString<B>> for KStringWriter
Source§fn extend<I: IntoIterator<Item = &'a KString<B>>>(&mut self, iter: I)
fn extend<I: IntoIterator<Item = &'a KString<B>>>(&mut self, iter: I)
Extends a collection with the contents of an iterator. Read more
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
🔬This is a nightly-only experimental API. (
extend_one
)Extends a collection with exactly one element.
Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
🔬This is a nightly-only experimental API. (
extend_one
)Reserves capacity in a collection for the given number of additional elements. Read more
Source§impl<'a, 's, B: HeapStr> Extend<&'a KStringCow<'s, B>> for KStringWriter
impl<'a, 's, B: HeapStr> Extend<&'a KStringCow<'s, B>> for KStringWriter
Source§fn extend<I: IntoIterator<Item = &'a KStringCow<'s, B>>>(&mut self, iter: I)
fn extend<I: IntoIterator<Item = &'a KStringCow<'s, B>>>(&mut self, iter: I)
Extends a collection with the contents of an iterator. Read more
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
🔬This is a nightly-only experimental API. (
extend_one
)Extends a collection with exactly one element.
Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
🔬This is a nightly-only experimental API. (
extend_one
)Reserves capacity in a collection for the given number of additional elements. Read more
Source§impl<'a, 's> Extend<&'a KStringRef<'s>> for KStringWriter
impl<'a, 's> Extend<&'a KStringRef<'s>> for KStringWriter
Source§fn extend<I: IntoIterator<Item = &'a KStringRef<'s>>>(&mut self, iter: I)
fn extend<I: IntoIterator<Item = &'a KStringRef<'s>>>(&mut self, iter: I)
Extends a collection with the contents of an iterator. Read more
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
🔬This is a nightly-only experimental API. (
extend_one
)Extends a collection with exactly one element.
Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
🔬This is a nightly-only experimental API. (
extend_one
)Reserves capacity in a collection for the given number of additional elements. Read more
Source§impl<'a> Extend<&'a char> for KStringWriter
impl<'a> Extend<&'a char> for KStringWriter
Source§fn extend<I: IntoIterator<Item = &'a char>>(&mut self, iter: I)
fn extend<I: IntoIterator<Item = &'a char>>(&mut self, iter: I)
Extends a collection with the contents of an iterator. Read more
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
🔬This is a nightly-only experimental API. (
extend_one
)Extends a collection with exactly one element.
Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
🔬This is a nightly-only experimental API. (
extend_one
)Reserves capacity in a collection for the given number of additional elements. Read more
Source§impl<'a> Extend<&'a str> for KStringWriter
impl<'a> Extend<&'a str> for KStringWriter
Source§fn extend<I: IntoIterator<Item = &'a str>>(&mut self, iter: I)
fn extend<I: IntoIterator<Item = &'a str>>(&mut self, iter: I)
Extends a collection with the contents of an iterator. Read more
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
🔬This is a nightly-only experimental API. (
extend_one
)Extends a collection with exactly one element.
Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
🔬This is a nightly-only experimental API. (
extend_one
)Reserves capacity in a collection for the given number of additional elements. Read more
Source§impl Extend<Box<str>> for KStringWriter
impl Extend<Box<str>> for KStringWriter
Source§fn extend<I: IntoIterator<Item = Box<str>>>(&mut self, iter: I)
fn extend<I: IntoIterator<Item = Box<str>>>(&mut self, iter: I)
Extends a collection with the contents of an iterator. Read more
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
🔬This is a nightly-only experimental API. (
extend_one
)Extends a collection with exactly one element.
Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
🔬This is a nightly-only experimental API. (
extend_one
)Reserves capacity in a collection for the given number of additional elements. Read more
Source§impl<'a> Extend<Cow<'a, str>> for KStringWriter
impl<'a> Extend<Cow<'a, str>> for KStringWriter
Source§fn extend<I: IntoIterator<Item = Cow<'a, str>>>(&mut self, iter: I)
fn extend<I: IntoIterator<Item = Cow<'a, str>>>(&mut self, iter: I)
Extends a collection with the contents of an iterator. Read more
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
🔬This is a nightly-only experimental API. (
extend_one
)Extends a collection with exactly one element.
Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
🔬This is a nightly-only experimental API. (
extend_one
)Reserves capacity in a collection for the given number of additional elements. Read more
Source§impl<B: HeapStr> Extend<KString<B>> for KStringWriter
impl<B: HeapStr> Extend<KString<B>> for KStringWriter
Source§fn extend<I: IntoIterator<Item = KString<B>>>(&mut self, iter: I)
fn extend<I: IntoIterator<Item = KString<B>>>(&mut self, iter: I)
Extends a collection with the contents of an iterator. Read more
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
🔬This is a nightly-only experimental API. (
extend_one
)Extends a collection with exactly one element.
Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
🔬This is a nightly-only experimental API. (
extend_one
)Reserves capacity in a collection for the given number of additional elements. Read more
Source§impl<'s, B: HeapStr> Extend<KStringCow<'s, B>> for KStringWriter
impl<'s, B: HeapStr> Extend<KStringCow<'s, B>> for KStringWriter
Source§fn extend<I: IntoIterator<Item = KStringCow<'s, B>>>(&mut self, iter: I)
fn extend<I: IntoIterator<Item = KStringCow<'s, B>>>(&mut self, iter: I)
Extends a collection with the contents of an iterator. Read more
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
🔬This is a nightly-only experimental API. (
extend_one
)Extends a collection with exactly one element.
Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
🔬This is a nightly-only experimental API. (
extend_one
)Reserves capacity in a collection for the given number of additional elements. Read more
Source§impl<'s> Extend<KStringRef<'s>> for KStringWriter
impl<'s> Extend<KStringRef<'s>> for KStringWriter
Source§fn extend<I: IntoIterator<Item = KStringRef<'s>>>(&mut self, iter: I)
fn extend<I: IntoIterator<Item = KStringRef<'s>>>(&mut self, iter: I)
Extends a collection with the contents of an iterator. Read more
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
🔬This is a nightly-only experimental API. (
extend_one
)Extends a collection with exactly one element.
Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
🔬This is a nightly-only experimental API. (
extend_one
)Reserves capacity in a collection for the given number of additional elements. Read more
Source§impl Extend<String> for KStringWriter
impl Extend<String> for KStringWriter
Source§fn extend<I: IntoIterator<Item = String>>(&mut self, iter: I)
fn extend<I: IntoIterator<Item = String>>(&mut self, iter: I)
Extends a collection with the contents of an iterator. Read more
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
🔬This is a nightly-only experimental API. (
extend_one
)Extends a collection with exactly one element.
Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
🔬This is a nightly-only experimental API. (
extend_one
)Reserves capacity in a collection for the given number of additional elements. Read more
Source§impl Extend<char> for KStringWriter
impl Extend<char> for KStringWriter
Source§fn extend<I: IntoIterator<Item = char>>(&mut self, iter: I)
fn extend<I: IntoIterator<Item = char>>(&mut self, iter: I)
Extends a collection with the contents of an iterator. Read more
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
🔬This is a nightly-only experimental API. (
extend_one
)Extends a collection with exactly one element.
Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
🔬This is a nightly-only experimental API. (
extend_one
)Reserves capacity in a collection for the given number of additional elements. Read more
Source§impl<B: HeapStr> From<KStringWriter> for KString<B>
impl<B: HeapStr> From<KStringWriter> for KString<B>
Source§fn from(writer: KStringWriter) -> Self
fn from(writer: KStringWriter) -> Self
Converts to this type from the input type.
Auto Trait Implementations§
impl Freeze for KStringWriter
impl RefUnwindSafe for KStringWriter
impl Send for KStringWriter
impl Sync for KStringWriter
impl Unpin for KStringWriter
impl UnwindSafe for KStringWriter
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoSql for T
impl<T> IntoSql for T
Source§fn into_sql<T>(self) -> Self::Expression
fn into_sql<T>(self) -> Self::Expression
Convert
self
to an expression for Diesel’s query builder. Read moreSource§fn as_sql<'a, T>(&'a self) -> <&'a Self as AsExpression<T>>::Expression
fn as_sql<'a, T>(&'a self) -> <&'a Self as AsExpression<T>>::Expression
Convert
&self
to an expression for Diesel’s query builder. Read more