Skip to main content

TypeMapper

Trait TypeMapper 

Source
pub trait TypeMapper {
    type L: Clone + Debug;
    type V: Clone + Debug;

    // Required methods
    fn label(&self, s: &str) -> Result<Self::L, String>;
    fn string_value(&self, s: &str) -> Result<Self::V, String>;
    fn num_value(&self, n: f64) -> Result<Self::V, String>;
    fn bool_value(&self, b: bool) -> Result<Self::V, String>;
    fn node_ref(&self, name: &str) -> Result<Self::V, String>;
}
Expand description

Maps DSL literal types to concrete pattern types.

The DSL parses labels as strings and values as strings/numbers/bools/node-refs. This trait bridges from those parsed representations to the target type system.

All methods return Result to support fallible mappings (e.g., looking up a string label in a predicate registry that may not contain the label).

§Example

struct WkMapper { labels: HashMap<String, u32> }

impl TypeMapper for WkMapper {
    type L = u32;
    type V = paracausality::Value;

    fn label(&self, s: &str) -> Result<u32, String> {
        self.labels.get(s).copied()
            .ok_or_else(|| format!("unknown predicate '{}'", s))
    }
    // ...
}

Required Associated Types§

Source

type L: Clone + Debug

The label type for patterns (e.g., String, u32).

Source

type V: Clone + Debug

The value type for patterns (e.g., MemValue, Value).

Required Methods§

Source

fn label(&self, s: &str) -> Result<Self::L, String>

Convert a label string to the target label type.

Source

fn string_value(&self, s: &str) -> Result<Self::V, String>

Convert a string literal to a value.

Source

fn num_value(&self, n: f64) -> Result<Self::V, String>

Convert a numeric literal to a value.

Source

fn bool_value(&self, b: bool) -> Result<Self::V, String>

Convert a boolean literal to a value.

Source

fn node_ref(&self, name: &str) -> Result<Self::V, String>

Convert a node reference to a value.

Implementors§