rusty_systems/
interpretation.rs

1use std::fmt::Debug;
2use crate::prelude::{ProductionString, RunSettings, System};
3use crate::symbols::SymbolStore;
4
5pub mod abop;
6pub mod svg;
7
8pub trait Interpretation: Debug + Sync + Send + Default {
9    type Item;
10
11    /// Returns a default system that can handle symbols that this Interpretation
12    /// understands.
13    ///
14    /// Note that an interpretation can [`Interpretation::interpret`] other
15    /// systems not produced by this function. THIS FUNCTION IS ONLY A CONVENIENCE
16    /// FUNCTION.
17    fn system() -> crate::Result<System>;
18
19    fn interpret<S: SymbolStore>(&self,
20                                 symbols: &S,
21                                 string: &ProductionString) -> crate::Result<Self::Item>;
22
23
24    fn default_interpret<S: SymbolStore>(symbols: &S,
25                                         string: &ProductionString) -> crate::Result<Self::Item> {
26        let instance = Self::default();
27        instance.interpret(symbols, string)
28    }
29
30    /// Returns default run settings for this interpretation.
31    ///
32    /// This defines how a system should be derived.
33    fn run_settings(&self) -> RunSettings {
34        RunSettings::default()
35    }
36
37}
38
39/// An interpretation that does nothing except
40#[derive(Debug, Clone, Default)]
41pub struct NullInterpretation {
42}
43
44impl NullInterpretation {
45}
46
47impl Interpretation for NullInterpretation {
48    type Item = ();
49
50    #[inline]
51    fn system() -> crate::Result<System> {
52        Ok(System::default())
53    }
54
55    #[inline]
56    fn interpret<S: SymbolStore>(&self, _: &S, _: &ProductionString) -> crate::Result<Self::Item> {
57        Ok(())
58    }
59}