Skip to main content

MessageRepository

Struct MessageRepository 

Source
pub struct MessageRepository { /* private fields */ }
Expand description

A tree of messages with one selected path, root to head.

Implementations§

Source§

impl MessageRepository

Source

pub fn new() -> Self

An empty repository.

Source

pub fn len(&self) -> usize

The number of messages in the tree, on every branch.

Source

pub fn is_empty(&self) -> bool

Whether the tree has no messages.

Source

pub fn contains(&self, id: &MessageId) -> bool

Whether a message with this id is in the tree.

Source

pub fn head_id(&self) -> Option<&MessageId>

The last message of the selected path.

Source

pub fn canonical_head_id(&self) -> Option<&MessageId>

The head after skipping optimistic messages.

Source

pub fn messages(&self) -> Arc<[Arc<ThreadMessage>]> ⓘ

The selected path from the root to the head.

Source

pub fn messages_to( &self, head_id: &MessageId, ) -> Result<Vec<Arc<ThreadMessage>>, RepositoryError>

The path from the root to head_id.

Source

pub fn get(&self, id: &MessageId) -> Result<MessageEntry, RepositoryError>

A message with its parent and depth.

Source

pub fn has_children(&self, id: &MessageId) -> bool

Whether the message has replies.

Source

pub fn branches(&self, id: &MessageId) -> Result<&[MessageId], RepositoryError>

The ids of the message and its siblings, in creation order.

Source

pub fn branch_position( &self, id: &MessageId, ) -> Result<(usize, usize), RepositoryError>

(position, count) of the message among its siblings, 1-based, without allocating (what a branch picker shows).

Source

pub fn message_changes_since(&self, version: Option<u64>) -> MessageChanges

Selected-message changes since version, with bounded bookkeeping. Call messages for a full read when indices is None. A consumer must also refresh global runtime state (running, capabilities), which is not part of this repository’s journal.

Source

pub fn shape_version(&self) -> u64

Changes whenever messages are added, moved or removed, or the selected path changes; not when a message is updated in place (streaming). While it is unchanged, every message keeps its branch position.

Source

pub fn add_or_update( &mut self, parent_id: Option<&MessageId>, message: impl Into<Arc<ThreadMessage>>, ) -> Result<(), RepositoryError>

Insert a new message after parent_id, or replace the stored message with the same id, moving it under parent_id if that changed.

Source

pub fn delete( &mut self, id: &MessageId, replacement: Option<Option<&MessageId>>, ) -> Result<(), RepositoryError>

Remove a message. Its children move to replacement: by default its parent, Some(None) for the root, or Some(Some(id)) for another message.

Source

pub fn switch_to_branch( &mut self, id: &MessageId, ) -> Result<(), RepositoryError>

Make the branch through id current, selecting its last-used descendants.

Source

pub fn reset_head( &mut self, id: Option<&MessageId>, ) -> Result<(), RepositoryError>

Make id the head and delete everything below it; None clears all.

Source

pub fn clear(&mut self)

Remove every message.

Source

pub fn export(&self) -> ExportedRepository

Persisted messages in parent-first order; optimistic ones are skipped and their children reattached to the nearest persisted ancestor.

Source

pub fn import( &mut self, exported: ExportedRepository, ) -> Result<(), RepositoryError>

Add or update every listed message (parents first), then select the listed head, or the last listed message.

Trait Implementations§

Source§

impl Default for MessageRepository

Source§

fn default() -> Self

Returns the “default value” for a type. 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> 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>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.