wagon_value/
lib.rs

1#![warn(missing_docs)]
2//! Pseudo-dynamically typed values for WAGon.
3//!
4//! Because of the strict type system in Rust, it's nice to have a more lenient data structure that can deal with various types and operations called on it.
5//! 
6//! This crate holds code for those purposes.
7
8mod value;
9mod valueable;
10mod result;
11
12extern crate self as wagon_value; // Have to do this to get the macro to work
13
14use std::fmt::Display;
15use wagon_macros::ValueOps;
16
17pub use value::{Value, Pow};
18pub use valueable::{Valueable, ToValue};
19pub use result::{ValueError, ValueResult};
20
21/// A [`Valueable`] that can hold a list/dict mapping to other values.
22///
23/// Because of recursion limits in Rust, [`Value`] can not be implemented over itself. 
24/// `RecursiveValue` is, for all intents and purposes, a `Value` implemented over itself. 
25///
26/// If the basic [`Value`] enum is enough for your purposes, you will want to use `RecursiveValue`.
27///
28/// # Example
29/// Instead of doing this: 
30/// ```
31/// use wagon_value::Value;
32/// ```
33/// Do this:
34/// ```
35/// use wagon_value::RecursiveValue as Value;
36/// ```
37#[derive(Debug, Eq, PartialEq, Hash, Clone, ValueOps, PartialOrd)]
38pub struct RecursiveValue(Value<RecursiveValue>);
39
40impl Display for RecursiveValue {
41    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
42        self.0.fmt(f)
43    }
44}
45
46impl ToValue<Self> for RecursiveValue {
47    fn to_value(&self) -> &Value<Self> {
48        &self.0
49    }
50}
51
52impl std::ops::Deref for RecursiveValue {
53    type Target = Value<Self>;
54
55    fn deref(&self) -> &Self::Target {
56        &self.0
57    }
58}
59
60impl From<Value<Self>> for RecursiveValue {
61    fn from(value: Value<Self>) -> Self {
62        Self(value)
63    }
64}
65
66impl From<RecursiveValue> for Value<RecursiveValue> {
67    fn from(value: RecursiveValue) -> Self {
68        value.0
69    }
70}