Skip to content

Commit 9a03ea4

Browse files
committed
feat(deep_causality_ast):
Added From reference impl to ConstTree Signed-off-by: Marvin Hansen <[email protected]>
1 parent 5d9d4c3 commit 9a03ea4

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

deep_causality_ast/src/const_tree/from.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,10 @@ impl<T> From<T> for ConstTree<T> {
1111
Self::new(value)
1212
}
1313
}
14+
// Egonomics for creating a leaf node from a reference,
15+
impl<T: Clone> From<&T> for ConstTree<T> {
16+
/// Creates a new leaf `ConstTree` by cloning the provided value.
17+
fn from(value: &T) -> Self {
18+
Self::new(value.clone())
19+
}
20+
}

deep_causality_ast/src/const_tree/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,10 @@ impl<T> ConstTree<T> {
106106
/// // The children are shared between the two trees.
107107
/// assert!(original.children()[0].ptr_eq(&with_new_value.children()[0]));
108108
/// ```
109-
pub fn with_value(&self, new_value: T) -> Self {
109+
pub fn with_value<V: Into<T>>(&self, new_value: V) -> Self {
110110
Self {
111111
node: Arc::new(Node {
112-
value: new_value,
112+
value: new_value.into(),
113113
children: self.node.children.clone(),
114114
}),
115115
}

0 commit comments

Comments
 (0)