From c95c69be4db23da7ab3205bc3ed2aa688fc45b58 Mon Sep 17 00:00:00 2001 From: ConnorSkees <39542938+ConnorSkees@users.noreply.github.com> Date: Mon, 6 Apr 2020 22:26:43 -0400 Subject: [PATCH] avoid unwrapping in special functions rgb/rgba one arg green --- src/builtin/color/rgb.rs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/builtin/color/rgb.rs b/src/builtin/color/rgb.rs index ca155e1..d43d5d3 100644 --- a/src/builtin/color/rgb.rs +++ b/src/builtin/color/rgb.rs @@ -53,9 +53,12 @@ pub(crate) fn register(f: &mut HashMap) { (n / Number::from(100)) * Number::from(255) } Some(v) if v.is_special_function() => { - let red = channels.pop().unwrap(); + let string = match channels.pop() { + Some(red) => format!("rgb({}, {}, {})", red, v, blue), + None => format!("rgb({}, {})", v, blue), + }; return Ok(Value::Ident( - format!("rgb({}, {}, {})", red, v, blue), + string, QuoteKind::None, )); } @@ -238,9 +241,12 @@ pub(crate) fn register(f: &mut HashMap) { (n / Number::from(100)) * Number::from(255) } Some(v) if v.is_special_function() => { - let red = channels.pop().unwrap(); + let string = match channels.pop() { + Some(red) => format!("rgba({}, {}, {})", red, v, blue), + None => format!("rgba({}, {})", v, blue), + }; return Ok(Value::Ident( - format!("rgba({}, {}, {})", red, v, blue), + string, QuoteKind::None, )); }