Entity

Trait Entity 

Source
pub trait Entity:
    Sized
    + Debug
    + DeserializeOwned
    + Serialize {
    type OperationData: Debug + OperationData + Clone + Serialize + DeserializeOwned;
    type HistoryStep: Debug + HistoryStep;
    type Timeline: Debug + Timeline<Self>;

    const TYPENAME: &str;
    const NAMESPACE: &str;
    const FORMAT_VERSION: usize;

    // Required methods
    fn operations(&self) -> &Operations<Self>
       where Self: Sized;
    fn create_time(&self) -> &Time
       where Self: Sized;
    fn edit_time(&self) -> &Time
       where Self: Sized;
    fn current_head(&self) -> &oid
       where Self: Sized;
    unsafe fn from_parts(
        operations: Operations<Self>,
        create_time: Time,
        edit_time: Time,
        current_head: ObjectId,
    ) -> Self
       where Self: Sized;

    // Provided methods
    fn id(&self) -> EntityId<Self>
       where Self: Sized { ... }
    fn snapshot(&self) -> Snapshot<Self> { ... }
}
Expand description

Entities are the “objects” that compose a Replica.

This trait provides the common functionality needed for each Entity.

Required Associated Constants§

Source

const TYPENAME: &str

The name of the entity (issue, pull-request, …), for human consumption.

Source

const NAMESPACE: &str

The namespace in git references (bugs, prs, …).

Source

const FORMAT_VERSION: usize

The expected format version number, that can be used for data migration/upgrade.

Required Associated Types§

Source

type OperationData: Debug + OperationData + Clone + Serialize + DeserializeOwned

The type of Operation this Entity uses.

Source

type HistoryStep: Debug + HistoryStep

A step in the history of a Snapshot's Timeline.

Source

type Timeline: Debug + Timeline<Self>

The complete timeline of an Snapshot of this Entity.

Required Methods§

Source

fn operations(&self) -> &Operations<Self>
where Self: Sized,

Return the Operations that compose this Entity.

Source

fn create_time(&self) -> &Time
where Self: Sized,

Return the lamport::Time that was set, when this Entity was first created.

Source

fn edit_time(&self) -> &Time
where Self: Sized,

Return the lamport::Time that was set, when this Entity was last edited.

Source

fn current_head(&self) -> &oid
where Self: Sized,

Return the commit object id of the last commit that added operations to this Entity.

Source

unsafe fn from_parts( operations: Operations<Self>, create_time: Time, edit_time: Time, current_head: ObjectId, ) -> Self
where Self: Sized,

Construct this instance from the data stored on disk.

This function cannot return an Error, because the previous decoding functions (e.g., Operation::from_value) should have already sorted out invalid values.

§Note

This function is probably not what you want. It is only useful, if your want to create this Entity from it’s on disk serialization (or from a cache.)

§Safety

You need to uphold following invariants:

  • The creation_time and edit_time must be valid for the repository at this time (i.e., they should have been computed through witnessing the other clocks.)
  • The current_head must be the actual current head (i.e., operations must be computable by starting a commit traversal from this point).

Provided Methods§

Source

fn id(&self) -> EntityId<Self>
where Self: Sized,

Return this Entity’s EntityId.

Source

fn snapshot(&self) -> Snapshot<Self>

Generate a snapshot of this Entity. This is a frozen collection of this Entity's Operations.

§Note

The generic Snapshot structure is extended by both identity and issue Entities with getters for their specific values.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§