Struct string_ring::StringRing

source ·
pub struct StringRing { /* private fields */ }
Expand description

A circular string buffer with a set maximum size.

Strings can be pushed onto the end of the buffer. If the maximum size would be exceeded, the oldest content will be removed to make space. The specific strategy for removing old content is defined by Granularity.

Implementations§

source§

impl StringRing

source

pub fn new(max_size: usize, granularity: Granularity) -> Self

Creates a new, empty StringRing with the given settings.

source

pub fn len(&self) -> usize

Gets the current size of the stored string.

source

pub fn is_empty(&self) -> bool

Checks if the buffer is empty.

source

pub fn clear(&mut self)

Removes all content from the buffer and resets it to the initial state.

source

pub fn as_slices(&self) -> (&[u8], &[u8])

Gets a reference to the raw stored data. Note that because this is a circular buffer of bytes, the content may be in two distinct pieces which may not independently be valid UTF-8 sequences. However, the two slices together (in the returned order) always represents a valid UTF-8 string.

source

pub fn make_contiguous(&mut self) -> &mut str

Makes the content of the circular buffer contiguous and returns it as a mutable slice.

source

pub fn push(&mut self, s: &str)

Appends content to the end of the buffer. If this would cause the buffer to exceed its maximum size, old content is removed to make room (as defined by Granularity).

It is guaranteed that pushing a followed by b is equivalent to pushing a + b. In Granularity::Line mode, this may lead to unexpected results if a does not end in a new line, as bytes may need to be discarded from the beginning of b to reach the end of a line being removed. This information is stored internally as a simple state machine to ensure stream consistency.

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

const: unstable · source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

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

const: unstable · 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, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
source§

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

§

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

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.