Session

Struct Session 

Source
pub struct Session<'a, A, T> { /* private fields */ }
Expand description

An editing session tied to one author.

Session provides a lot of functions you might know from Vec or VecDeque. Under the hood, Session will append changes to the chronofolds log.

Note that Session has a mutable (exclusive) borrow of a chronofold. So Rust’s ownership rules enforce that there is always just one Session per chronofold.

Implementations§

Source§

impl<'a, A: Author, T> Session<'a, A, T>

Source

pub fn new(author: A, chronofold: &'a mut Chronofold<A, T>) -> Self

Creates an editing session for a single author.

Source

pub fn clear(&mut self)

Clears the chronofold, removing all elements.

Source

pub fn push_back(&mut self, value: T) -> LogIndex

Appends an element to the back of the chronofold and returns the new element’s log index.

Source

pub fn push_front(&mut self, value: T) -> LogIndex

Prepends an element to the chronofold and returns the new element’s log index.

Source

pub fn insert_after(&mut self, index: LogIndex, value: T) -> LogIndex

Inserts an element after the element with log index index and returns the new element’s log index.

If index == None, the element will be inserted at the beginning.

Source

pub fn remove(&mut self, index: LogIndex)

Removes the element with log index index from the chronofold.

Note that this just marks the element as deleted, not actually modify the log apart from appending a Change::Delete.

Source

pub fn extend<I: IntoIterator<Item = T>>(&mut self, iter: I) -> Option<LogIndex>

Extends the chronofold with the contents of iter, returns the log index of the last inserted element, if any.

Source

pub fn splice<R, I>(&mut self, range: R, replace_with: I) -> Option<LogIndex>
where I: IntoIterator<Item = T>, R: RangeBounds<LogIndex>,

Replaces the specified range in the chronofold with the given replace_with iterator and returns the log index of the last inserted element, if any.

Source

pub fn create_root(&mut self) -> LogIndex

Source

pub fn iter_ops<V>(&'a self) -> impl Iterator<Item = Op<A, V>> + 'a
where V: FromLocalValue<'a, A, T> + 'a,

Returns an iterator over ops in log order, that where created in this session.

Trait Implementations§

Source§

impl<A: Author, T> AsMut<Chronofold<A, T>> for Session<'_, A, T>

Source§

fn as_mut(&mut self) -> &mut Chronofold<A, T>

Converts this type into a mutable reference of the (usually inferred) input type.
Source§

impl<A: Author, T> AsRef<Chronofold<A, T>> for Session<'_, A, T>

Source§

fn as_ref(&self) -> &Chronofold<A, T>

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<'a, A: Debug, T: Debug> Debug for Session<'a, A, T>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a, A, T> Freeze for Session<'a, A, T>
where A: Freeze,

§

impl<'a, A, T> RefUnwindSafe for Session<'a, A, T>

§

impl<'a, A, T> Send for Session<'a, A, T>
where A: Send, T: Send,

§

impl<'a, A, T> Sync for Session<'a, A, T>
where A: Sync, T: Sync,

§

impl<'a, A, T> Unpin for Session<'a, A, T>
where A: Unpin,

§

impl<'a, A, T> !UnwindSafe for Session<'a, A, T>

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<A, T, V> IntoLocalValue<A, T> for V
where V: Into<T>,

Source§

fn into_local_value(self, _chronofold: &Chronofold<A, T>) -> T

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.