eryon_actors/drivers/
mod.rs

1/*
2    Appellation: drivers <module>
3    Contrib: @FL03
4*/
5//! this module works to provide various _drivers_ (a.k.a. plants) for each of the partitions
6//! (virtual nodes) within the substrate.
7#[doc(inline)]
8pub use self::plant::Plant;
9
10mod plant;
11
12pub(crate) mod prelude {
13    pub use super::plant::Plant;
14    pub use super::{Driver, RawDriver, TriadDriver};
15    pub use super::{NeuralPlant, WolframPlant};
16}
17
18use crate::engine::RawEngine;
19use crate::nrt::{LPR, Triad};
20
21/// A type alias for a plant with a neural engine
22pub type NeuralPlant<T = f32> = Plant<crate::engine::NeuralEngine<T>>;
23/// A type alias for a plant with a Wolfram [2, 3] UTM engine
24pub type WolframPlant<Q = usize, S = usize> = Plant<crate::engine::WolframUTM<Q, S>>;
25
26/// The raw driver trait defines the common interface for all plants. Drivers are fundamental
27/// to the operation of the framework as they equip virtualized entities with various
28/// abilities, such as computability.
29pub trait RawDriver<C>: Send + Sync + core::fmt::Debug {
30    type Engine: RawEngine;
31
32    fn engine(&self) -> &Self::Engine;
33
34    fn engine_mut(&mut self) -> &mut Self::Engine;
35
36    fn headspace(&self) -> &C;
37
38    fn headspace_mut(&mut self) -> &mut C;
39
40    private!();
41}
42
43/// The driver trait extends the raw driver trait by adding the ability to clone and
44/// synchronize the driver. This is useful for creating multiple instances of the same
45/// driver and for sharing the driver across threads.
46///
47/// The driver trait also provides various creation routines based on known parameters.
48pub trait Driver<H>: RawDriver<H>
49where
50    Self: Clone + Default,
51{
52    /// create a new driver with the given headspace
53    fn from_headspace(headspace: H) -> Self;
54}
55
56/// specific methods for [`triad`](Triad)-based drivers
57pub trait TriadDriver: Driver<Triad> {
58    fn transform(&mut self, transform: LPR) -> Result<(), crate::ActorError>;
59
60    fn walk<'a, I>(&mut self, iter: I) -> Result<(), crate::ActorError>
61    where
62        I: IntoIterator<Item = &'a LPR>;
63}