taskchampion

Struct 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 TaskData or Task types. The first is a lower-level type that wraps the key-value store representing a task, while the second is a higher-level type that supports methods to update specific properties, maintain dependencies and tags, and so on.

§Operations

Changes to a replica occur by committing Operationss. All methods that change a replica take an argument of type &mut Operations, and the necessary operations are added to that sequence. Those changes may be reflected locally, such as in a Task or TaskData value, but are not reflected in the Replica’s storage until committed with Replica::commit_operations.

Undo is supported by producing an Operations value representing the operations to be undone. These are then committed with Replica::commit_reversed_operations.

§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 can be “renumbered” when necessary.

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

👎Deprecated since 0.7.0: please use TaskData instead

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.

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_data(&mut self) -> Result<HashMap<Uuid, TaskData>, Error>

Get all task represented as a map of TaskData keyed by UUID

Source

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

Get the UUIDs of all tasks

Source

pub fn pending_tasks(&mut self) -> Result<Vec<Task>, Error>

Get an array containing all pending tasks

Source

pub fn pending_task_data(&mut self) -> Result<Vec<TaskData>, Error>

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<Arc<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.

Calculating this value requires a scan of the full working set and may not be performant. The TaskData API avoids generating this value.

Source

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

Get an existing task by its UUID

Source

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

Get an existing task by its UUID, as a TaskData.

Source

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

Get the operations that led to the given task.

This set of operations is suitable for providing an overview of the task history, but does not satisfy any invariants around operations and task state. That is, it is not guaranteed that the returned operations, if applied in order, would generate the current task state.

It is also not guaranteed to be the same on every replica. Differences can occur when conflicting operations were performed on different replicas. The “losing” operations in those conflicts may not appear on all replicas. In practice, conflicts are rare and the results of this function will be the same on all replicas for most tasks.

Source

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

👎Deprecated since 0.7.0: please use create_task and call Task methods set_status, set_description, and set_entry

Create a new task, setting modified, description, status, and entry.

This uses the high-level task interface. To create a task with the low-level interface, use TaskData::create.

Source

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

Create a new task.

Use [’Uuid::new_v4`] to invent a new task ID, if necessary. If the task already exists, it is returned.

Source

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

👎Deprecated since 0.7.0: please use TaskData instead

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

Source

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

👎Deprecated since 0.7.0: please use TaskData::delete

Delete a task. The task must exist. Note that this is different from setting status to Deleted; this is the final purge of the task.

Deletion may interact poorly with modifications to the same task on other replicas. For example, if a task is deleted on replica 1 and its description modified on replica 1, then after both replicas have fully synced, the resulting task will only have a description property.

Source

pub fn commit_operations(&mut self, operations: Operations) -> Result<(), Error>

Commit a set of operations to the replica.

All local state on the replica will be updated accordingly, including the working set and and temporarily cached data.

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_operations(&mut self) -> Result<Operations, Error>

Return the operations back to and including the last undo point, or since the last sync if no undo point is found.

The operations are returned in the order they were applied. Use Replica::commit_reversed_operations to “undo” them.

Source

pub fn commit_reversed_operations( &mut self, operations: Operations, ) -> Result<bool, Error>

Commit the reverse of the given operations, beginning with the last operation in the given operations and proceeding to the first.

This method only supports reversing operations if they precisely match local operations that have not yet been synchronized, and will return false if this is not the case.

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>

👎Deprecated since 0.7.0: Push an Operation::UndoPoint onto your Operations instead.

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

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<Unshared, Shared> IntoShared<Shared> for Unshared
where Shared: FromUnshared<Unshared>,

Source§

fn into_shared(self) -> Shared

Creates a shared type from an unshared type.
Source§

impl<T> Same for T

Source§

type Output = T

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

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> MaybeSendSync for T