Skip to main content

Replica

Struct Replica 

pub struct Replica<R>
where R: Resource,
{ /* private fields */ }
Expand description

One replica of an R resource. See the module docs.

Implementations§

§

impl<R> Replica<R>
where R: Resource,

pub fn new() -> Replica<R>

A new resource, initialized as a new record would be.

§Panics

Panics when Resource::initialize fails, which is a bug in the resource type under test.

pub fn from_doc(doc: AutoCommit) -> Replica<R>

A replica of an existing document.

pub fn load(bytes: &[u8]) -> Result<Replica<R>, ModelError>

A replica of a document saved as bytes: a file’s contents.

§Errors

Returns [ModelError::Automerge] when the bytes hold no document.

pub fn save(&mut self) -> Vec<u8> ⓘ

The document as bytes, for a file that carries the resource whole.

pub fn as_author(self, author: &str) -> Replica<R>

Attribute later actions to author, as the host does for a signed-in collaborator.

pub fn as_invoker(self, author: &str) -> Replica<R>

Attribute later actions to author invoking from this replica, as the host does for a person at one of their devices: what a verb reads as ActionCx::author, while the changes stay this replica’s own, so the same person on two replicas makes changes that merge.

pub fn as_agent_for(self, agent: &str, person: &str) -> Replica<R>

Attribute later actions to the agent agent acting for person, as a host does for an agent’s calls.

pub fn as_bot_for(self, installation: &str, installer: &str) -> Replica<R>

Attribute later actions to the bot installation installation acting for installer, as a bot host does for a bot’s calls.

pub fn showing(self, appearance: Appearance) -> Replica<R>

Show appearance for the bot’s later actions, as a bot host admits a bridge’s post under another name.

pub fn in_app(self, id: &str, label: &str) -> Replica<R>

Name id (labelled label) as the app later actions are in, as the host running the app does: every member decides them against that app’s surface.

pub fn set_now_ms(&mut self, now_ms: i64)

Set the origin clock later actions are stamped with.

pub fn published(&self) -> Result<Resource, ModelError>

The tree the resource publishes now: what the door resolves against.

§Errors

Returns [ModelError] when the document does not hold the resource.

pub fn apply( &mut self, invoke: impl Into<Invoke<R>>, ) -> Result<&ActionEnvelope, DoorError>

Invoke a published action exactly as a control, the palette, an agent or a script does: through the door, which refuses one that asks for confirmation (Self::apply_confirmed).

§Errors

Returns the door’s refusal: unknown, unavailable, invalid arguments, confirmation required, or the action’s own refusal.

pub fn apply_confirmed( &mut self, invoke: impl Into<Invoke<R>>, ) -> Result<&ActionEnvelope, DoorError>

Self::apply after the person confirmed it.

§Errors

As Self::apply, without asking for confirmation.

pub fn apply_action( &mut self, action: &<R as Resource>::Action, ) -> Result<&ActionEnvelope, DoorError>

Apply one typed action value, the path a custom surface takes once its person confirmed what it does: the generic APPLY action, through the door.

§Errors

Returns the door’s refusal or the action’s own.

pub fn replay(&mut self, envelope: &ActionEnvelope) -> Result<(), ActionError>

Replay an envelope authored on another replica.

§Errors

Returns a decode or apply error.

pub fn state(&self) -> Result<<R as Resource>::State, ModelError>

The current state.

§Errors

Returns [ModelError] when the document does not hold the resource.

pub fn live(&mut self) -> Result<&<R as Resource>::State, ModelError>

The state as a view sees it: read once, then kept current by applying only what each change touched (Resource::refresh) and reading what is demanded (Resource::load). A test comparing it with Self::state proves the resource’s incremental reads exact.

§Errors

Returns [ModelError] when the document does not hold the resource.

pub fn demand( &mut self, demand: Demand, ) -> Result<&<R as Resource>::State, ModelError>
where <R as Resource>::State: Clone,

Ask the view state of Self::live for the parts demand names.

§Errors

Returns [ModelError] when the document does not hold the resource.

pub fn fork(&mut self) -> Replica<R>

A second replica sharing this one’s history, as a collaborator who just joined would hold.

pub fn sync_with(&mut self, other: &mut Replica<R>) -> Result<(), ModelError>

Exchange every change with other, as sync does.

§Errors

Returns a document error.

pub fn log(&self) -> &[ActionEnvelope]

Every envelope applied or replayed here, in order.

pub fn doc(&self) -> &AutoCommit

pub fn doc_mut(&mut self) -> &mut AutoCommit

The document, for a test that changes it the way something outside the resource’s actions would (a restore, a raw merge).

pub fn heads(&mut self) -> Vec<ChangeHash>

pub fn versions(&mut self) -> Vec<Version>

The version history.

pub fn state_at( &mut self, heads: &[ChangeHash], ) -> Result<<R as Resource>::State, ModelError>

The state as of heads.

§Errors

Returns [ModelError] when that version does not hold the resource.

Trait Implementations§

§

impl<R> Default for Replica<R>
where R: Resource,

§

fn default() -> Replica<R>

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<R> Freeze for Replica<R>

§

impl<R> !RefUnwindSafe for Replica<R>

§

impl<R> !Send for Replica<R>

§

impl<R> !Sync for Replica<R>

§

impl<R> Unpin for Replica<R>

§

impl<R> UnsafeUnpin for Replica<R>

§

impl<R> !UnwindSafe for Replica<R>

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
§

impl<T> Downcast<T> for T

§

fn downcast(&self) -> &T

§

impl<T> Downcast for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

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

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

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
§

impl<T> NoneValue for T
where T: Default,

§

type NoneType = T

§

fn null_value() -> T

The none-equivalent value.
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
§

impl<T, S> SimdFrom<T, S> for T
where S: Simd,

§

fn simd_from(_simd: S, value: T) -> T

§

impl<F, T, S> SimdInto<T, S> for F
where T: SimdFrom<F, S>, S: Simd,

§

fn simd_into(self, simd: S) -> 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.
§

impl<T> Upcast<T> for T

§

fn upcast(&self) -> Option<&T>

§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

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

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