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 = fn(
14 Box<dyn ScriptContext>,
15 Value,
16) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'static>>;
17
18pub struct ScriptDescriptor {
23 pub name: &'static str,
25 pub invoke: InvokeFn,
27 pub signature_json: &'static str,
29 pub signature_hash: u64,
31}
32
33impl ScriptDescriptor {
34 pub const fn new(name: &'static str, invoke: InvokeFn) -> Self {
36 Self {
37 name,
38 invoke,
39 signature_json: "{}",
40 signature_hash: 0,
41 }
42 }
43
44 pub const fn with_signature(
46 name: &'static str,
47 invoke: InvokeFn,
48 signature_json: &'static str,
49 signature_hash: u64,
50 ) -> Self {
51 Self {
52 name,
53 invoke,
54 signature_json,
55 signature_hash,
56 }
57 }
58}
59
60impl std::fmt::Debug for ScriptDescriptor {
61 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
62 f.debug_struct("ScriptDescriptor")
63 .field("name", &self.name)
64 .field("signature_json", &self.signature_json)
65 .field("signature_hash", &self.signature_hash)
66 .field("invoke", &"<fn>")
67 .finish()
68 }
69}
70
71quark::inventory::collect!(ScriptDescriptor);
72
73impl quark::Registrable for ScriptDescriptor {
74 fn registry_key(&self) -> &str {
75 self.name
76 }
77}