From 1d01b93f679bccf8f228616bcf0f0ebcdee64d98 Mon Sep 17 00:00:00 2001 From: Laurenz Date: Wed, 13 Jan 2021 15:44:41 +0100 Subject: =?UTF-8?q?Move=20comment=20tests=20to=20integration=20?= =?UTF-8?q?=F0=9F=9A=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/eval/call.rs | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) (limited to 'src/eval/call.rs') diff --git a/src/eval/call.rs b/src/eval/call.rs index 186e7630..a2387a17 100644 --- a/src/eval/call.rs +++ b/src/eval/call.rs @@ -59,13 +59,16 @@ impl Eval for Spanned<&ExprArgs> { /// Evaluated arguments to a function. #[derive(Debug)] pub struct Args { - span: Span, - pos: SpanVec, - named: Vec<(Spanned, Spanned)>, + /// The span of the whole argument list. + pub span: Span, + /// The positional arguments. + pub pos: SpanVec, + /// The named arguments. + pub named: Vec<(Spanned, Spanned)>, } impl Args { - /// Find the first convertible positional argument. + /// Find and remove the first convertible positional argument. pub fn find(&mut self, ctx: &mut EvalContext) -> Option where T: Cast>, @@ -73,8 +76,8 @@ impl Args { self.pos.iter_mut().find_map(move |slot| try_cast(ctx, slot)) } - /// Find the first convertible positional argument, producing an error if - /// no match was found. + /// Find and remove the first convertible positional argument, producing an + /// error if no match was found. pub fn require(&mut self, ctx: &mut EvalContext, what: &str) -> Option where T: Cast>, @@ -86,7 +89,7 @@ impl Args { found } - /// Filter out all convertible positional arguments. + /// Filter out and remove all convertible positional arguments. pub fn filter<'a, T>( &'a mut self, ctx: &'a mut EvalContext, @@ -97,8 +100,8 @@ impl Args { self.pos.iter_mut().filter_map(move |slot| try_cast(ctx, slot)) } - /// Convert the value for the given named argument, producing an error if - /// the conversion fails. + /// Convert and remove the value for the given named argument, producing an + /// error if the conversion fails. pub fn get<'a, T>(&mut self, ctx: &mut EvalContext, name: &str) -> Option where T: Cast>, @@ -108,6 +111,13 @@ impl Args { cast(ctx, value) } + /// Drain all remainings arguments into an array and a dictionary. + pub fn drain(&mut self) -> (ValueArray, ValueDict) { + let array = self.pos.drain(..).map(|s| s.v).collect(); + let dict = self.named.drain(..).map(|(k, v)| (k.v, v.v)).collect(); + (array, dict) + } + /// Produce "unexpected argument" errors for all remaining arguments. pub fn finish(self, ctx: &mut EvalContext) { let a = self.pos.iter().map(|v| v.as_ref()); -- cgit v1.2.3