Struct input_mgr::RingLine

source ·
pub struct RingLine<const L: usize, const C: usize> { /* private fields */ }
Expand description

§RingLine

The RingLine structure contains the textual history of a two entity conversation

It is generic over two numbers:

  • L is the number of lines it can store
  • C is the maximum number of ASCII characters per line

In general, L should be >= the number of lines you intend to display. If L is larger than the number of lines you would like to display, it can also be used as a “scrollback” buffer.

RingLine does NOT store lines in a “sparse” manner - if you have 16 lines and 80 characters per line, 1280 bytes will be used to store those characters, even if all lines are blank.

Implementations§

source§

impl<const L: usize, const C: usize> RingLine<L, C>

source

pub fn new() -> Self

source

pub fn iter_history(&self) -> LineIter<'_, L, Line<C>>

Iterates all “historical” (e.g. not currently editing) lines, NEWEST to OLDEST

Each line contans a status field that marks it as local or remote.

The returned iterator implements DoubleEndedIterator, and can be reversed with Iterator::rev() to obtain lines in OLDEST to NEWEST order.

source

pub fn iter_remote_editing(&self) -> LineIter<'_, L, Line<C>>

Iterates any lines that are currently being edited by the remote end, NEWEST to OLDEST

The returned iterator implements DoubleEndedIterator, and can be reversed with Iterator::rev() to obtain lines in OLDEST to NEWEST order.

source

pub fn local_editing_len(&self) -> usize

The number of ascii characters/bytes currently used by the local editing buffer

source

pub fn remote_editing_len(&self) -> usize

The number of ascii characters/bytes currently used by the remote editing buffer

source

pub fn copy_local_editing_to<'a>( &self, buffer: &'a mut [u8], ) -> Result<&'a mut [u8], LineError>

Attempt to copy the entire current local editing buffer to a provided slice

Useful for obtaining the full user input prior to submitting the line.

Returns an error if the provided slice is not large enough to contain the entire local editing buffer contents. Otherwise, returns a subslice that contains the used contents of the provided slice. The length of this slice will be the same as the length returned by RingLine::local_editing_len().

If you do not need the entire contents in a single slice, consider using RingLine::iter_local_editing() and calling rev() to get the contents oldest to newest.

source

pub fn iter_local_editing(&self) -> LineIter<'_, L, Line<C>>

Iterates any lines that are currently being edited by the local end, NEWEST to OLDEST

The returned iterator implements DoubleEndedIterator, and can be reversed with Iterator::rev() to obtain lines in OLDEST to NEWEST order.

source

pub fn iter_remote_editing_mut(&mut self) -> LineIterMut<'_, '_, L, Line<C>>

Iterates any lines that are currently being edited by the remote end, NEWEST to OLDEST

The returned iterator implements DoubleEndedIterator, and can be reversed with Iterator::rev() to obtain lines in OLDEST to NEWEST order.

source

pub fn iter_local_editing_mut(&mut self) -> LineIterMut<'_, '_, L, Line<C>>

Iterates any lines that are currently being edited by the local end, NEWEST to OLDEST

The returned iterator implements DoubleEndedIterator, and can be reversed with Iterator::rev() to obtain lines in OLDEST to NEWEST order.

source

pub fn submit_local_editing(&mut self)

Moves the local editing region into a user historical region

source

pub fn submit_remote_editing(&mut self)

Moves the remote editing region into a user historical region

source

pub fn append_local_char(&mut self, c: u8) -> Result<(), RingLineError>

Attempts to append a character to the local editing region

Does NOT accept control characters, such as \n.

source

pub fn append_remote_char(&mut self, c: u8) -> Result<(), RingLineError>

Attempts to append a character to the remote editing region

Does NOT accept control characters, such as \n.

source

pub fn pop_local_char(&mut self)

Attempts to remove a character from the local editing region

source

pub fn pop_remote_char(&mut self)

Attempts to remove a character from the local editing region

Trait Implementations§

source§

impl<const L: usize, const C: usize> Debug for RingLine<L, C>

source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<const L: usize, const C: usize> Freeze for RingLine<L, C>

§

impl<const L: usize, const C: usize> RefUnwindSafe for RingLine<L, C>

§

impl<const L: usize, const C: usize> Send for RingLine<L, C>

§

impl<const L: usize, const C: usize> Sync for RingLine<L, C>

§

impl<const L: usize, const C: usize> Unpin for RingLine<L, C>

§

impl<const L: usize, const C: usize> UnwindSafe for RingLine<L, C>

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> 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, U> TryFrom<U> for T
where U: Into<T>,

§

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>,

§

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.