pub struct BehaviorController {}
Expand description

The BehaviorController API provides functionality for interacting with external behavior modules

Implementations§

source§

impl BehaviorController

source

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();
source

pub fn list_behavior_modules(&self) -> ListModulesFuture

Starts an asynchronous retrieval of a list of behavior modules from the connected remote module store.

The completed future returns a serialized JSON vector of bytes with a list of BehaviorModuleMeta

Example
use ark_api::behavior_controller::BehaviorModuleMeta;

let json_bytes = behavior_controller().list_behavior_modules().await?;
let metadatas: Vec<BehaviorModuleMeta> = serde_json::from_slice(&json_bytes).unwrap();
source

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:

  1. 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.
  2. A behavior instance will then process the just received message.
  3. During the processing of a message, a behavior instance can create new OutgoingMessages 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.

source

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

source

pub fn aspect_remove(&self, removes: &[AspectAddr])

Requests multiple aspect removals. If the aspect store doesn’t exist, nothing happens

source

pub fn aspect_reset_all(&self)

Reset all existing aspect stores to their initial states

source

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.

source

pub fn load_behavior_module( &self, id: &BehaviorModuleId ) -> Result<LoadModuleFuture, Error>

Starts an asynchronous retrieval of a behavior module from the module store

Trait Implementations§

source§

impl Clone for BehaviorController

source§

fn clone(&self) -> BehaviorController

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Copy for BehaviorController

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · 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> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.