summaryrefslogtreecommitdiff
path: root/src/model/methods.rs
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2022-12-21 23:48:04 +0100
committerLaurenz <laurmaedje@gmail.com>2022-12-21 23:48:04 +0100
commit1eda162867afab656ec9b95c85f725cd676d4f04 (patch)
treee349d3ddb709701c9997fead0869c5390fbb3ec4 /src/model/methods.rs
parent038f9b015ee1248c3636c5e1b2edb5c4767ed837 (diff)
Mutable methods with return values
Diffstat (limited to 'src/model/methods.rs')
-rw-r--r--src/model/methods.rs11
1 files changed, 7 insertions, 4 deletions
diff --git a/src/model/methods.rs b/src/model/methods.rs
index fc33bea9..dac36be2 100644
--- a/src/model/methods.rs
+++ b/src/model/methods.rs
@@ -128,9 +128,10 @@ pub fn call_mut(
method: &str,
mut args: Args,
span: Span,
-) -> SourceResult<()> {
+) -> SourceResult<Value> {
let name = value.type_name();
let missing = || Err(missing_method(name, method)).at(span);
+ let mut output = Value::None;
match value {
Value::Array(array) => match method {
@@ -139,12 +140,14 @@ pub fn call_mut(
"insert" => {
array.insert(args.expect("index")?, args.expect("value")?).at(span)?
}
- "remove" => array.remove(args.expect("index")?).at(span)?,
+ "remove" => output = array.remove(args.expect("index")?).at(span)?,
_ => return missing(),
},
Value::Dict(dict) => match method {
- "remove" => dict.remove(&args.expect::<EcoString>("key")?).at(span)?,
+ "remove" => {
+ output = dict.remove(&args.expect::<EcoString>("key")?).at(span)?
+ }
_ => return missing(),
},
@@ -152,7 +155,7 @@ pub fn call_mut(
}
args.finish()?;
- Ok(())
+ Ok(output)
}
/// Whether a specific method is mutating.