Struct ark_api::behavior_controller::BehaviorController
source · [−]pub struct BehaviorController {}
Expand description
The BehaviorController
API provides functionality for interacting with external behavior modules
Implementations
sourceimpl BehaviorController
impl BehaviorController
sourcepub fn list_modules(&self) -> Vec<u8>
pub fn list_modules(&self) -> Vec<u8>
Returns a serialized JSON vector of bytes with a list of external registration info.
Only registration info from behavior modules listed in a Cargo.toml’s Ark annotation will be returned
Example
At a bare minimum, the JSON vector can be deserialized into a vector of BehaviorModuleRegistration
:
use ark_api::behavior_controller::BehaviorModuleRegistration;
let list: Vec<BehaviorModuleRegistration> = serde_json::from_slice(behavior_controller().list_modules()).unwrap();
If behavior modules were registered with a custom registration format they can be deserialized similarly:
use ark_api::behavior_controller::BehaviorModuleRegistration;
// Custom data format used in behavior module registration
#[derive(serde::Deserialize)]
pub struct CustomBehaviorInfo {
#[serde(flatten)]
pub info: BehaviorModuleRegistration,
pub port_names: Vec<String>,
pub tag_names: Vec<String>,
}
let list: Vec<CustomBehaviorInfo> = serde_json::from_slice(behavior_controller().list_modules()).unwrap();
sourcepub fn instances_handle_messages(
&self,
messages: &[IncomingMessage<'_>]
) -> OutgoingMessages
pub fn instances_handle_messages(
&self,
messages: &[IncomingMessage<'_>]
) -> OutgoingMessages
Have the specified instances process the provided messages
This is key functionality of the Behavior Controller API as it will kick off processing of messages for behavior instances in external behavior modules.
The following will happen after a call to instances_handle_messages
:
- In order, Ark will extract the
IncomingMessage
’s address and send the message data to the correct behavior instance owned by some external behavior module. - A behavior instance will then process the just received message.
- During the processing of a message, a behavior instance can create new
OutgoingMessage
s that will be returned to the user of this API.
The user can then turn outgoing messages into incoming messages and repeat the above process.
sourcepub fn aspect_upsert(&self, upserts: &[AspectUpsert<'_>])
pub fn aspect_upsert(&self, upserts: &[AspectUpsert<'_>])
Requests multiple insertions or updates in aspect stores; if an aspect doesn’t exist, it’s seamlessly created on the host
sourcepub fn aspect_remove(&self, removes: &[AspectAddr])
pub fn aspect_remove(&self, removes: &[AspectAddr])
Requests multiple aspect removals. If the aspect store doesn’t exist, nothing happens
sourcepub fn aspect_reset_all(&self)
pub fn aspect_reset_all(&self)
Reset all existing aspect stores to their initial states
sourcepub fn publish(&self, id: &BehaviorModuleId) -> Result<BehaviorModuleId, Error>
pub fn publish(&self, id: &BehaviorModuleId) -> Result<BehaviorModuleId, Error>
Publishes the module with the given ID and returns a possibly different ID of the published version.
If the module is already published nothing will happen and the function will return the same ID as the one provided as an argument.
sourcepub fn load_behavior_module(
&self,
id: &BehaviorModuleId
) -> Result<Vec<u8>, Error>
pub fn load_behavior_module(
&self,
id: &BehaviorModuleId
) -> Result<Vec<u8>, Error>
Loads the module with the given ID.
Returns a serialized JSON vector of bytes containing the external registration info for the loaded module.
Trait Implementations
sourceimpl Clone for BehaviorController
impl Clone for BehaviorController
sourcefn clone(&self) -> BehaviorController
fn clone(&self) -> BehaviorController
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
impl Copy for BehaviorController
Auto Trait Implementations
impl RefUnwindSafe for BehaviorController
impl Send for BehaviorController
impl Sync for BehaviorController
impl Unpin for BehaviorController
impl UnwindSafe for BehaviorController
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more