avoid unwrapping in special functions rgb/rgba one arg green

This commit is contained in:
ConnorSkees 2020-04-06 22:26:43 -04:00
parent 65ba25e555
commit c95c69be4d

View File

@ -53,9 +53,12 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
(n / Number::from(100)) * Number::from(255) (n / Number::from(100)) * Number::from(255)
} }
Some(v) if v.is_special_function() => { 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( return Ok(Value::Ident(
format!("rgb({}, {}, {})", red, v, blue), string,
QuoteKind::None, QuoteKind::None,
)); ));
} }
@ -238,9 +241,12 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
(n / Number::from(100)) * Number::from(255) (n / Number::from(100)) * Number::from(255)
} }
Some(v) if v.is_special_function() => { 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( return Ok(Value::Ident(
format!("rgba({}, {}, {})", red, v, blue), string,
QuoteKind::None, QuoteKind::None,
)); ));
} }