pub trait BehaviorEntry {
// Required methods
fn register(&mut self) -> Vec<u8> ⓘ;
fn persist(&mut self) -> Vec<u8> ⓘ;
fn restore(&mut self, state: &[u8]);
fn instance_create(
&mut self,
local_type_id: LocalBehaviorTypeId,
ron_params: &str,
) -> ForeignBehaviorInstanceId;
fn instance_destroy(&mut self, instance_id: ForeignBehaviorInstanceId);
fn instance_clone(
&mut self,
instance_id: ForeignBehaviorInstanceId,
) -> ForeignBehaviorInstanceId;
fn instance_persist(
&self,
instance_id: ForeignBehaviorInstanceId,
) -> Vec<u8> ⓘ;
fn instance_restore(
&mut self,
local_type_id: LocalBehaviorTypeId,
blob: &[u8],
) -> ForeignBehaviorInstanceId;
fn instance_handle_message(
&mut self,
addr: IncomingMessageAddr,
serialized_message: &[u8],
);
// Provided method
fn instances_handle_messages<'a>(
&mut self,
messages: impl ExactSizeIterator<Item = IncomingMessage<'a>>,
) { ... }
}Expand description
Ergonomic wrapper around a behavior module’s entry points.
See the module level documentation for an explanation on the various identifiers used in this trait
Required Methods§
Sourcefn register(&mut self) -> Vec<u8> ⓘ
fn register(&mut self) -> Vec<u8> ⓘ
Should return a serialized JSON vector of bytes of local registration info.
§Example
use ark_module::behavior::{LocalBehaviorRegistration, LocalModuleRegistration};
fn register(&self) -> Vec<u8> {
let behavior_info = LocalBehaviorRegistration{
type_id: 0,
name: String::from("test123"),
};
let registration_info = LocalModuleRegistration{
behavior_infos: vec![behavior_info],
};
serde_json::to_vec(®istration_info).unwrap()
}Users can return custom registration data by including LocalModuleRegistration
and tagging it with #[serde(flatten)].
use ark_module::behavior::{LocalBehaviorRegistration, LocalModuleRegistration};
#[derive(serde::Deserialize)]
pub struct CustomRegistrationInfo {
#[serde(flatten)]
pub registration_info: LocalModuleRegistration,
pub custom_string: String,
pub custom_uint: u32,
}
fn register(&self) -> Vec<u8> {
let behavior_info = LocalBehaviorRegistration{
type_id: 0,
name: String::from("test123"),
};
let registration_info = LocalModuleRegistration{
behavior_infos: vec![behavior_info],
};
let custom_registration_info = CustomRegistrationInfo {
registration_info,
custom_string: String::from("test456"),
custom_uint: 1,
};
}Sourcefn persist(&mut self) -> Vec<u8> ⓘ
fn persist(&mut self) -> Vec<u8> ⓘ
Persists a whole module after it failed, before an attempt to reload it and re-run it. In particular, the module should keep an account of all the cleanups it should run after restoring is done.
Sourcefn restore(&mut self, state: &[u8])
fn restore(&mut self, state: &[u8])
Restores a module serialized with persist. The module should run additional cleanups at
this point.
Sourcefn instance_create(
&mut self,
local_type_id: LocalBehaviorTypeId,
ron_params: &str,
) -> ForeignBehaviorInstanceId
fn instance_create( &mut self, local_type_id: LocalBehaviorTypeId, ron_params: &str, ) -> ForeignBehaviorInstanceId
Construct a new LocalBehaviorInstanceId given the type id and ron parameters,
which can then be packed into a ForeignBehaviorInstanceId and returned here.
Sourcefn instance_destroy(&mut self, instance_id: ForeignBehaviorInstanceId)
fn instance_destroy(&mut self, instance_id: ForeignBehaviorInstanceId)
Destroys the provided instance in the behavior module
Sourcefn instance_clone(
&mut self,
instance_id: ForeignBehaviorInstanceId,
) -> ForeignBehaviorInstanceId
fn instance_clone( &mut self, instance_id: ForeignBehaviorInstanceId, ) -> ForeignBehaviorInstanceId
Clones the provided instance in the behavior module
Sourcefn instance_persist(&self, instance_id: ForeignBehaviorInstanceId) -> Vec<u8> ⓘ
fn instance_persist(&self, instance_id: ForeignBehaviorInstanceId) -> Vec<u8> ⓘ
Serialize the instance’s state into a binary blob
Sourcefn instance_restore(
&mut self,
local_type_id: LocalBehaviorTypeId,
blob: &[u8],
) -> ForeignBehaviorInstanceId
fn instance_restore( &mut self, local_type_id: LocalBehaviorTypeId, blob: &[u8], ) -> ForeignBehaviorInstanceId
Restore an instance given the provided type id and serialized state
Sourcefn instance_handle_message(
&mut self,
addr: IncomingMessageAddr,
serialized_message: &[u8],
)
fn instance_handle_message( &mut self, addr: IncomingMessageAddr, serialized_message: &[u8], )
Have the provided instance handle the incoming serialized message
Provided Methods§
Sourcefn instances_handle_messages<'a>(
&mut self,
messages: impl ExactSizeIterator<Item = IncomingMessage<'a>>,
)
fn instances_handle_messages<'a>( &mut self, messages: impl ExactSizeIterator<Item = IncomingMessage<'a>>, )
Process the incoming messages
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.