From 1eda162867afab656ec9b95c85f725cd676d4f04 Mon Sep 17 00:00:00 2001 From: Laurenz Date: Wed, 21 Dec 2022 23:48:04 +0100 Subject: Mutable methods with return values --- src/model/methods.rs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'src/model/methods.rs') 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 { 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::("key")?).at(span)?, + "remove" => { + output = dict.remove(&args.expect::("key")?).at(span)? + } _ => return missing(), }, @@ -152,7 +155,7 @@ pub fn call_mut( } args.finish()?; - Ok(()) + Ok(output) } /// Whether a specific method is mutating. -- cgit v1.2.3