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,
impl<R> Replica<R>where
R: Resource,
pub fn new() -> Replica<R>
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>
pub fn from_doc(doc: AutoCommit) -> Replica<R>
A replica of an existing document.
pub fn save(&mut self) -> Vec<u8> ⓘ
pub fn save(&mut self) -> Vec<u8> ⓘ
The document as bytes, for a file that carries the resource whole.
Attribute later actions to author, as the host does for a signed-in
collaborator.
pub fn as_invoker(self, author: &str) -> Replica<R>
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>
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>
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>
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>
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)
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>
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>
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>
pub fn apply_confirmed( &mut self, invoke: impl Into<Invoke<R>>, ) -> Result<&ActionEnvelope, DoorError>
pub fn apply_action(
&mut self,
action: &<R as Resource>::Action,
) -> Result<&ActionEnvelope, DoorError>
pub fn apply_action( &mut self, action: &<R as Resource>::Action, ) -> Result<&ActionEnvelope, DoorError>
pub fn replay(&mut self, envelope: &ActionEnvelope) -> Result<(), ActionError>
pub fn replay(&mut self, envelope: &ActionEnvelope) -> Result<(), ActionError>
pub fn live(&mut self) -> Result<&<R as Resource>::State, ModelError>
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>
pub fn demand( &mut self, demand: Demand, ) -> Result<&<R as Resource>::State, ModelError>
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>
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 log(&self) -> &[ActionEnvelope]
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
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>
Trait Implementations§
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
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>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
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)
fn as_any(&self) -> &(dyn Any + 'static)
&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)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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