From 0c1a2f4499cd8599d6d6b362feb413bad16d0ee4 Mon Sep 17 00:00:00 2001 From: Jeff Date: Fri, 8 Mar 2024 16:22:24 -0500 Subject: [PATCH] Remove implicit cloning for string values --- src/abstract_tree/if_else.rs | 4 ++-- src/value.rs | 4 ++-- tests/statements.rs | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/abstract_tree/if_else.rs b/src/abstract_tree/if_else.rs index 6343b5d..84270ff 100644 --- a/src/abstract_tree/if_else.rs +++ b/src/abstract_tree/if_else.rs @@ -75,7 +75,7 @@ mod tests { None ) .run(&Context::new()), - Ok(Action::Return(Value::string("foo"))) + Ok(Action::Return(Value::string("foo".to_string()))) ) } @@ -90,7 +90,7 @@ mod tests { )))) ) .run(&Context::new()), - Ok(Action::Return(Value::string("bar"))) + Ok(Action::Return(Value::string("bar".to_string()))) ) } } diff --git a/src/value.rs b/src/value.rs index a28ad5b..bb2f978 100644 --- a/src/value.rs +++ b/src/value.rs @@ -64,8 +64,8 @@ impl Value { Value(Arc::new(ValueInner::Range(range))) } - pub fn string(string: T) -> Self { - Value(Arc::new(ValueInner::String(string.to_string()))) + pub fn string(string: String) -> Self { + Value(Arc::new(ValueInner::String(string))) } pub fn r#enum(name: Identifier, variant: Identifier) -> Self { diff --git a/tests/statements.rs b/tests/statements.rs index b0e3caa..14ce920 100644 --- a/tests/statements.rs +++ b/tests/statements.rs @@ -15,7 +15,7 @@ fn loops_and_breaks() { } " ), - Ok(Some(Value::string("foobar"))) + Ok(Some(Value::string("foobar".to_string()))) ) } @@ -23,7 +23,7 @@ fn loops_and_breaks() { fn r#if() { assert_eq!( interpret("if true 'foobar'"), - Ok(Some(Value::string("foobar"))) + Ok(Some(Value::string("foobar".to_string()))) ) } @@ -31,6 +31,6 @@ fn r#if() { fn if_else() { assert_eq!( interpret("if false 'foo' else 'bar'"), - Ok(Some(Value::string("bar"))) + Ok(Some(Value::string("bar".to_string()))) ) }