fj_kernel/services/
objects.rs

1use crate::objects::{Object, Objects, WithHandle};
2
3use super::State;
4
5impl State for Objects {
6    type Command = Operation;
7    type Event = InsertObject;
8
9    fn decide(&self, command: Self::Command, events: &mut Vec<Self::Event>) {
10        let Operation::InsertObject { object } = command;
11        events.push(InsertObject { object });
12    }
13
14    fn evolve(&mut self, event: &Self::Event) {
15        event.object.clone().insert(self);
16    }
17}
18
19/// Command for `Service<Objects>`
20#[derive(Debug)]
21pub enum Operation {
22    /// Insert an object into the stores
23    ///
24    /// This is the one primitive operation that all other operations are built
25    /// upon.
26    InsertObject {
27        /// The object to insert
28        object: Object<WithHandle>,
29    },
30}
31
32/// Event produced by `Service<Objects>`
33#[derive(Clone, Debug)]
34pub struct InsertObject {
35    /// The object to insert
36    pub object: Object<WithHandle>,
37}