Skip to main content

context_engine/
required.rs

1// required.rs: modules required to implement
2
3use core::primitive::usize;
4use alloc::collections::BTreeMap;
5use crate::provided::Tree;
6
7#[derive(Debug)]
8pub enum SetOutcome {
9    Created(usize),
10    Updated,
11}
12
13/// A store provides addressed access to values.
14pub trait Store {
15    fn get(
16        &self,
17        key: &[u8],
18        args: &BTreeMap<&str, Tree>,
19    ) -> Option<Tree>;
20
21    fn set(
22        &self,
23        key: &[u8],
24        args: &BTreeMap<&str, Tree>,
25    ) -> Option<SetOutcome>;
26
27    fn delete(
28        &self,
29        key: &[u8],
30        args: &BTreeMap<&str, Tree>,
31    ) -> bool;
32}
33
34/// Maps compile-time store_id (u8) to a `Store` implementation.
35/// The id corresponds to the index position in the `store_ids` slice passed to `Dsl::compile`.
36pub trait Stores {
37    fn store_for(&self, id: u8) -> Option<&dyn Store>;
38}