str_stack

Struct StrStack

Source
pub struct StrStack { /* private fields */ }

Implementations§

Source§

impl StrStack

Source

pub fn new() -> StrStack

Create a new StrStack.

Source

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.

Source

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.

Source

pub fn iter(&self) -> Iter<'_>

Iterate over the strings on the stack.

Source

pub fn pop(&mut self) -> bool

Remove the top string from the stack.

Returns true iff a string was removed.

Source

pub fn clear(&mut self)

Clear the stack.

Source

pub fn len(&self) -> usize

Returns the number of strings on the stack.

Source

pub fn truncate(&mut self, len: usize)

Truncate the stack to len strings.

Source

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.

Source

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!");
Source

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!");
Source

pub unsafe fn get_unchecked(&self, index: usize) -> &str

Trait Implementations§

Source§

impl Clone for StrStack

Source§

fn clone(&self) -> StrStack

Returns a copy 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 Debug for StrStack

Source§

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

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

impl Default for StrStack

Source§

fn default() -> StrStack

Returns the “default value” for a type. Read more
Source§

impl<S> Extend<S> for StrStack
where S: AsRef<str>,

Source§

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)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
Source§

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
where S: AsRef<str>,

Source§

fn from_iter<T>(iterator: T) -> Self
where T: IntoIterator<Item = S>,

Creates a value from an iterator. Read more
Source§

impl Index<usize> for StrStack

Source§

type Output = str

The returned type after indexing.
Source§

fn index(&self, index: usize) -> &str

Performs the indexing (container[index]) operation. Read more
Source§

impl<'a> IntoIterator for &'a StrStack

Source§

type IntoIter = Iter<'a>

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

type Item = &'a str

The type of the elements being iterated over.
Source§

fn into_iter(self) -> Iter<'a>

Creates an iterator from a value. Read more

Auto Trait Implementations§

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, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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, 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.