pub struct StrStack { /* private fields */ }
Implementations§
Source§impl StrStack
impl StrStack
Sourcepub fn with_capacity(bytes: usize, strings: usize) -> StrStack
pub fn with_capacity(bytes: usize, strings: usize) -> StrStack
Create a new StrStack with the given capacity.
You will be able to push bytes
bytes and create strings
strings before reallocating.
Sourcepub fn push(&mut self, s: &str) -> usize
pub fn push(&mut self, s: &str) -> usize
Push a string onto the string stack.
This returns the index of the string on the stack.
Sourcepub fn pop(&mut self) -> bool
pub fn pop(&mut self) -> bool
Remove the top string from the stack.
Returns true iff a string was removed.
Sourcepub fn consume<R: Read>(&mut self, source: R) -> Result<usize>
pub fn consume<R: Read>(&mut self, source: R) -> Result<usize>
Read from source
into the string stack.
Returns the index of the new string or an IO Error.
Sourcepub fn writer(&mut self) -> Writer<'_>
pub fn writer(&mut self) -> Writer<'_>
Returns a writer helper for this string stack.
This is useful for building a string in-place on the string-stack.
Example:
use std::fmt::Write;
use str_stack::StrStack;
let mut s = StrStack::new();
let index = {
let mut writer = s.writer();
writer.write_str("Hello");
writer.write_char(' ');
writer.write_str("World");
writer.write_char('!');
writer.finish()
};
assert_eq!(&s[index], "Hello World!");
Sourcepub fn write_fmt(&mut self, args: Arguments<'_>) -> usize
pub fn write_fmt(&mut self, args: Arguments<'_>) -> usize
Allows calling the write! macro directly on the string stack:
Example:
use std::fmt::Write;
use str_stack::StrStack;
let mut s = StrStack::new();
let index = write!(&mut s, "Hello {}!", "World");
assert_eq!(&s[index], "Hello World!");
pub unsafe fn get_unchecked(&self, index: usize) -> &str
Trait Implementations§
Source§impl<S> Extend<S> for StrStack
impl<S> Extend<S> for StrStack
Source§fn extend<T>(&mut self, iterator: T)where
T: IntoIterator<Item = S>,
fn extend<T>(&mut self, iterator: T)where
T: IntoIterator<Item = S>,
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> FromIterator<S> for StrStack
impl<S> FromIterator<S> for StrStack
Source§fn from_iter<T>(iterator: T) -> Selfwhere
T: IntoIterator<Item = S>,
fn from_iter<T>(iterator: T) -> Selfwhere
T: IntoIterator<Item = S>,
Creates a value from an iterator. Read more
Auto Trait Implementations§
impl Freeze for StrStack
impl RefUnwindSafe for StrStack
impl Send for StrStack
impl Sync for StrStack
impl Unpin for StrStack
impl UnwindSafe for StrStack
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§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit
)