Skip to content

Commit a45e58e

Browse files
authored
Merge pull request #57 from mathstuf/value-into-static
Value: add an `into_static` method
2 parents d72812f + 562bd4d commit a45e58e

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/common.rs

+20
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,26 @@ pub enum Value<'a, T: Text<'a>> {
5858
Object(BTreeMap<T::Value, Value<'a, T>>),
5959
}
6060

61+
impl<'a, T: Text<'a>> Value<'a, T> {
62+
pub fn into_static(&self) -> Value<'static, String> {
63+
match self {
64+
Self::Variable(v) => Value::Variable(v.as_ref().into()),
65+
Self::Int(i) => Value::Int(i.clone()),
66+
Self::Float(f) => Value::Float(*f),
67+
Self::String(s) => Value::String(s.clone()),
68+
Self::Boolean(b) => Value::Boolean(*b),
69+
Self::Null => Value::Null,
70+
Self::Enum(v) => Value::Enum(v.as_ref().into()),
71+
Self::List(l) => {
72+
Value::List(l.iter().map(|e| e.into_static()).collect())
73+
},
74+
Self::Object(o) => {
75+
Value::Object(o.iter().map(|(k, v)| (k.as_ref().into(), v.into_static())).collect())
76+
},
77+
}
78+
}
79+
}
80+
6181
#[derive(Debug, Clone, PartialEq)]
6282
pub enum Type<'a, T: Text<'a>> {
6383
NamedType(T::Value),

0 commit comments

Comments
 (0)