Struct ActionRegistry
pub struct ActionRegistry { /* private fields */ }Expand description
Maps a stable type_id to the decoder that reconstructs its action
from a payload — cheap to share behind an Arc/& at dispatch time.
Implementations§
§impl ActionRegistry
impl ActionRegistry
pub fn new() -> ActionRegistry
pub fn with(register: impl FnOnce(&mut ActionRegistry)) -> ActionRegistry
pub fn with(register: impl FnOnce(&mut ActionRegistry)) -> ActionRegistry
A registry holding what register adds, such as an app’s action set.
pub fn register<A>(&mut self, type_id: impl Into<String>)where
A: Action + DeserializeOwned + 'static,
pub fn register<A>(&mut self, type_id: impl Into<String>)where
A: Action + DeserializeOwned + 'static,
Register A under type_id; a later decode of an
EncodedAction carrying this type_id deserializes the payload
into an A and boxes it as dyn Action.
pub fn register_decoder(
&mut self,
type_id: impl Into<String>,
decode: fn(&[u8]) -> Result<Box<dyn Action>, Error>,
)
pub fn register_decoder( &mut self, type_id: impl Into<String>, decode: fn(&[u8]) -> Result<Box<dyn Action>, Error>, )
Register decode under type_id, for an action type that decodes
its payload itself, such as one generic type whose payload one
non-generic function decodes for every instance.
pub fn decode(
&self,
encoded: &EncodedAction,
) -> Result<Box<dyn Action>, ActionError>
pub fn decode( &self, encoded: &EncodedAction, ) -> Result<Box<dyn Action>, ActionError>
Reconstruct a live action from its encoded form.
§Errors
Returns ActionError::UnknownType if no decoder is registered
for encoded.type_id, or ActionError::Decode if the payload
fails to deserialize into the registered type.
pub fn set_content(
&mut self,
read: impl Fn(&str) -> Option<Vec<u8>> + Send + Sync + 'static,
)
pub fn set_content( &mut self, read: impl Fn(&str) -> Option<Vec<u8>> + Send + Sync + 'static, )
Read the large parts of recorded actions from read (the device’s
content store), so a change whose action names content replays.
Without one, the thread’s reader (crate::keep_content_in) is used.
pub fn resolve(
&self,
recorded: &EncodedAction,
) -> Result<Result<EncodedAction, MissingContent>, ActionError>
pub fn resolve( &self, recorded: &EncodedAction, ) -> Result<Result<EncodedAction, MissingContent>, ActionError>
The recorded action recorded as it ran, its content parts read
from this registry’s content reader.
§Errors
MissingContent for content not here yet
(inside Ok), or a payload that is not JSON.
Trait Implementations§
§impl Default for ActionRegistry
impl Default for ActionRegistry
§fn default() -> ActionRegistry
fn default() -> ActionRegistry
Auto Trait Implementations§
impl Freeze for ActionRegistry
impl !RefUnwindSafe for ActionRegistry
impl Send for ActionRegistry
impl Sync for ActionRegistry
impl Unpin for ActionRegistry
impl UnsafeUnpin for ActionRegistry
impl !UnwindSafe for ActionRegistry
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> DowncastSync for T
impl<T> DowncastSync for T
§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