Skip to main content

harmos_domain/state/
catalog.rs

1/* ***
2 *
3 * Harmos
4 *
5 * SPDX-License-Identifier: Apache-2.0
6 *
7 * ***
8 */
9
10/* === Modules === */
11
12/* === Re-Exports === */
13
14/* === Imports === */
15
16// Standard Library Imports
17
18// Third Party Imports
19
20// Local Imports
21use super::{DecodeError, Kind};
22use crate::DefinitionId;
23
24/* === Constants === */
25
26/* === Macros === */
27
28/* === Type Aliases === */
29
30pub type TransactionDecoder<T> = fn(&DefinitionId, u32, &[u8]) -> Result<Option<T>, DecodeError>;
31pub type Inverse<S, T> = fn(&T, &S) -> Option<T>;
32
33/* === Structs === */
34
35pub struct TransactionDefinitions<S, T> {
36    pub definitions: Vec<(Kind, DefinitionId, u32)>,
37    pub decode: TransactionDecoder<T>,
38    pub inverses: Inverse<S, T>,
39}
40
41pub struct RecordDefinitions<R> {
42    pub definitions: Vec<(Kind, DefinitionId, u32)>,
43    pub marker: std::marker::PhantomData<fn() -> R>,
44}
45
46/* === Enums === */
47
48/* === Traits === */
49
50/* === Implementations === */
51
52impl<S, T> Clone for TransactionDefinitions<S, T> {
53    fn clone(&self) -> Self {
54        Self { definitions: self.definitions.clone(), decode: self.decode, inverses: self.inverses }
55    }
56}
57
58impl<R> Clone for RecordDefinitions<R> {
59    fn clone(&self) -> Self {
60        Self { definitions: self.definitions.clone(), marker: std::marker::PhantomData }
61    }
62}
63
64/* === Public Functions === */
65
66/* === Private Functions === */
67
68/* === Tests === */