From 118fc1014bcfc5585fd3ce32348fbfe14bdc05a9 Mon Sep 17 00:00:00 2001 From: Laurenz Date: Tue, 18 May 2021 21:32:40 +0200 Subject: Leaner argument parsing --- src/library/basic.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src/library/basic.rs') diff --git a/src/library/basic.rs b/src/library/basic.rs index 48925122..a094f039 100644 --- a/src/library/basic.rs +++ b/src/library/basic.rs @@ -11,7 +11,7 @@ use super::*; /// # Return value /// The name of the value's type as a string. pub fn type_(ctx: &mut EvalContext, args: &mut FuncArgs) -> Value { - match args.require::(ctx, "value") { + match args.eat_expect::(ctx, "value") { Some(value) => value.type_name().into(), None => Value::Error, } @@ -25,7 +25,7 @@ pub fn type_(ctx: &mut EvalContext, args: &mut FuncArgs) -> Value { /// # Return value /// The string representation of the value. pub fn repr(ctx: &mut EvalContext, args: &mut FuncArgs) -> Value { - match args.require::(ctx, "value") { + match args.eat_expect::(ctx, "value") { Some(value) => pretty(&value).into(), None => Value::Error, } @@ -42,10 +42,10 @@ pub fn repr(ctx: &mut EvalContext, args: &mut FuncArgs) -> Value { /// # Return value /// The color with the given components. pub fn rgb(ctx: &mut EvalContext, args: &mut FuncArgs) -> Value { - let r = args.require(ctx, "red component"); - let g = args.require(ctx, "green component"); - let b = args.require(ctx, "blue component"); - let a = args.find(ctx); + let r = args.eat_expect(ctx, "red component"); + let g = args.eat_expect(ctx, "green component"); + let b = args.eat_expect(ctx, "blue component"); + let a = args.eat(ctx); let mut clamp = |component: Option>, default| { component.map_or(default, |c| { -- cgit v1.2.3