chronon_executor/
descriptor.rs1use std::future::Future;
4use std::pin::Pin;
5
6use chronon_core::{Result, ScriptContext};
7use serde_json::Value;
8
9pub type InvokeFn =
14 fn(Box<dyn ScriptContext>, Value) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'static>>;
15
16pub struct ScriptDescriptor {
21 pub name: &'static str,
23 pub invoke: InvokeFn,
25 pub signature_json: &'static str,
27 pub signature_hash: u64,
29}
30
31impl ScriptDescriptor {
32 pub const fn new(name: &'static str, invoke: InvokeFn) -> Self {
34 Self {
35 name,
36 invoke,
37 signature_json: "{}",
38 signature_hash: 0,
39 }
40 }
41
42 pub const fn with_signature(
44 name: &'static str,
45 invoke: InvokeFn,
46 signature_json: &'static str,
47 signature_hash: u64,
48 ) -> Self {
49 Self {
50 name,
51 invoke,
52 signature_json,
53 signature_hash,
54 }
55 }
56}
57
58impl std::fmt::Debug for ScriptDescriptor {
59 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
60 f.debug_struct("ScriptDescriptor")
61 .field("name", &self.name)
62 .field("signature_json", &self.signature_json)
63 .field("signature_hash", &self.signature_hash)
64 .field("invoke", &"<fn>")
65 .finish()
66 }
67}
68
69quark::inventory::collect!(ScriptDescriptor);
70
71impl quark::Registrable for ScriptDescriptor {
72 fn registry_key(&self) -> &str {
73 self.name
74 }
75}