pub struct Extender { /* private fields */ }Implementations§
Source§impl Extender
impl Extender
Sourcepub fn register_var<T: ActUserVar + Clone + 'static>(&self, module: &T)
pub fn register_var<T: ActUserVar + Clone + 'static>(&self, module: &T)
register module
§Example
use acts::Engine;
mod test_module {
use acts::{ActUserVar, Vars, Result};
#[derive(Clone)]
pub struct TestModule;
impl ActUserVar for TestModule {
fn name(&self) -> String {
"my_var".to_string()
}
fn default_data(&self) -> Option<Vars> {
None
}
}
}
let engine = Engine::new().start();
let module = test_module::TestModule;
engine.extender().register_var(&module);Sourcepub fn register_package(&self, meta: &ActPackageMeta) -> Result<()>
pub fn register_package(&self, meta: &ActPackageMeta) -> Result<()>
register package with meta definition
§Example
use acts::{ActPackage, ActPackageMeta, Vars};
use serde::{Deserialize, Serialize};
use serde_json::json;
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct MyPackage {
a: i32,
b: Vec<String>,
}
impl ActPackage for MyPackage {
fn meta() -> ActPackageMeta {
ActPackageMeta {
name: "my_package",
desc: "",
icon: "",
doc: "",
version: "0.1.0",
schema: json!({
"type": "object",
"properties": {
"a": { "type": "number" },
"b": { "type": "array" }
}
}),
run_as: acts::ActRunAs::Irq,
resources: vec![],
catalog: acts::ActPackageCatalog::App,
}
}
}
#[tokio::main]
async fn main() {
let engine = acts::Engine::new().start();
engine.extender().register_package(&MyPackage::meta());
}Sourcepub fn register_collection<DATA>(
&self,
collection: Arc<dyn DbCollection<Item = DATA> + Send + Sync + 'static>,
)where
DATA: DbCollectionIden + 'static,
pub fn register_collection<DATA>(
&self,
collection: Arc<dyn DbCollection<Item = DATA> + Send + Sync + 'static>,
)where
DATA: DbCollectionIden + 'static,
register collection
§Example
use acts::{Engine, Result, DbCollection, data};
use std::sync::Arc;
pub struct MyCollection;
impl DbCollection for MyCollection {
type Item = data::Event;
fn exists(&self, id: &str) -> Result<bool> {
Ok(true)
}
fn find(&self, id: &str) -> Result<Self::Item> {
Ok(data::Event {
id: todo!(),
name: todo!(),
mid: todo!(),
ver: todo!(),
uses: todo!(),
params: todo!(),
create_time: todo!(),
timestamp: todo!(),
})
}
fn query(&self, q: &acts::query::Query) -> Result<acts::PageData<Self::Item>> {
Ok(acts::PageData {
count: 0,
page_num: 0,
page_count: 0,
page_size: 0,
rows: vec![],
})
}
fn create(&self, data: &Self::Item) -> Result<bool> {
Ok(true)
}
fn update(&self, data: &Self::Item) -> Result<bool> {
Ok(true)
}
fn delete(&self, id: &str) -> Result<bool> {
Ok(true)
}
}
#[tokio::main]
async fn main() {
let engine = acts::Engine::new().start();
let collection: Arc<dyn DbCollection<Item = data::Event> + Send + Sync> = Arc::new(MyCollection);
engine.extender().register_collection(collection);
}Trait Implementations§
Auto Trait Implementations§
impl Freeze for Extender
impl !RefUnwindSafe for Extender
impl Send for Extender
impl Sync for Extender
impl Unpin for Extender
impl UnsafeUnpin for Extender
impl !UnwindSafe for Extender
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
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§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>
Converts
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>
Converts
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