Struct taskchampion::Replica

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

A replica represents an instance of a user’s task data, providing an easy interface for querying and modifying that data.

§Tasks

Tasks are uniquely identified by UUIDs. Most task modifications are performed via the Task and TaskMut types. Use of two types for tasks allows easy read-only manipulation of lots of tasks, with exclusive access required only for modifications.

§Working Set

A replica maintains a “working set” of tasks that are of current concern to the user, specifically pending tasks. These are indexed with small, easy-to-type integers. Newly pending tasks are automatically added to the working set, and the working set is “renumbered” during the garbage-collection process.

Implementations§

source§

impl Replica

source

pub fn new(storage: Box<dyn Storage>) -> Replica

source

pub fn update_task<S1, S2>( &mut self, uuid: Uuid, property: S1, value: Option<S2> ) -> Result<TaskMap, Error>
where S1: Into<String>, S2: Into<String>,

Update an existing task. If the value is Some, the property is added or updated. If the value is None, the property is deleted. It is not an error to delete a nonexistent property.

This is a low-level method, and requires knowledge of the Task data model. Prefer to use the [TaskMut] methods to modify tasks, where possible.

source

pub fn all_tasks(&mut self) -> Result<HashMap<Uuid, Task>, Error>

Get all tasks represented as a map keyed by UUID

source

pub fn all_task_uuids(&mut self) -> Result<Vec<Uuid>, Error>

Get the UUIDs of all tasks

source

pub fn working_set(&mut self) -> Result<WorkingSet, Error>

Get the “working set” for this replica. This is a snapshot of the current state, and it is up to the caller to decide how long to store this value.

source

pub fn dependency_map( &mut self, force: bool ) -> Result<Rc<DependencyMap>, Error>

Get the dependency map for all pending tasks.

A task dependency is recognized when a task in the working set depends on a task with status equal to Pending.

The data in this map is cached when it is first requested and may not contain modifications made locally in this Replica instance. The result is reference-counted and may outlive the Replica.

If force is true, then the result is re-calculated from the current state of the replica, although previously-returned dependency maps are not updated.

source

pub fn get_task(&mut self, uuid: Uuid) -> Result<Option<Task>, Error>

Get an existing task by its UUID

source

pub fn new_task( &mut self, status: Status, description: String ) -> Result<Task, Error>

Create a new task.

source

pub fn import_task_with_uuid(&mut self, uuid: Uuid) -> Result<Task, Error>

Create a new, empty task with the given UUID. This is useful for importing tasks, but otherwise should be avoided in favor of new_task. If the task already exists, this does nothing and returns the existing task.

source

pub fn sync( &mut self, server: &mut Box<dyn Server>, avoid_snapshots: bool ) -> Result<(), Error>

Synchronize this replica against the given server. The working set is rebuilt after this occurs, but without renumbering, so any newly-pending tasks should appear in the working set.

If avoid_snapshots is true, the sync operations produces a snapshot only when the server indicate it is urgent (snapshot urgency “high”). This allows time for other replicas to create a snapshot before this one does.

Set this to true on systems more constrained in CPU, memory, or bandwidth than a typical desktop system

source

pub fn get_undo_ops(&mut self) -> Result<Vec<ReplicaOp>, Error>

Return undo local operations until the most recent UndoPoint, returning an empty Vec if there are no local operations to undo.

source

pub fn commit_undo_ops( &mut self, undo_ops: Vec<ReplicaOp> ) -> Result<bool, Error>

Undo local operations in storage, returning a boolean indicating success.

source

pub fn rebuild_working_set(&mut self, renumber: bool) -> Result<(), Error>

Rebuild this replica’s working set, based on whether tasks are pending or not. If renumber is true, then existing tasks may be moved to new working-set indices; in any case, on completion all pending and recurring tasks are in the working set and all tasks with other statuses are not.

source

pub fn expire_tasks(&mut self) -> Result<(), Error>

Expire old, deleted tasks.

Expiration entails removal of tasks from the replica. Any modifications that occur after the deletion (such as operations synchronized from other replicas) will do nothing.

Tasks are eligible for expiration when they have status Deleted and have not been modified for 180 days (about six months). Note that completed tasks are not eligible.

source

pub fn add_undo_point(&mut self, force: bool) -> Result<(), Error>

Add an UndoPoint, if one has not already been added by this Replica. This occurs automatically when a change is made. The force flag allows forcing a new UndoPoint even if one has already been created by this Replica, and may be useful when a Replica instance is held for a long time and used to apply more than one user-visible change.

source

pub fn num_local_operations(&mut self) -> Result<usize, Error>

Get the number of operations local to this replica and not yet synchronized to the server.

source

pub fn num_undo_points(&mut self) -> Result<usize, Error>

Get the number of undo points available (number of times undo will succeed).

Auto Trait Implementations§

§

impl Freeze for Replica

§

impl !RefUnwindSafe for Replica

§

impl !Send for Replica

§

impl !Sync for Replica

§

impl Unpin for Replica

§

impl !UnwindSafe for Replica

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> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Same for T

§

type Output = T

Should always be Self
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.
source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more