lewp_css/domain/at_rules/font_feature_values/
pair_values.rs1use {
5 crate::{
6 parsers::{Parse, ParserContext},
7 CustomParseError,
8 },
9 cssparser::{ParseError, Parser, ToCss, Token},
10 std::fmt,
11};
12
13#[derive(Clone, Debug, PartialEq)]
15pub struct PairValues(pub u32, pub Option<u32>);
16
17impl Parse for PairValues {
18 fn parse<'i, 't>(
19 _context: &ParserContext,
20 input: &mut Parser<'i, 't>,
21 ) -> Result<PairValues, ParseError<'i, CustomParseError<'i>>> {
22 let first = match *input.next()? {
23 Token::Number {
24 int_value: Some(firstValue),
25 ..
26 } if firstValue >= 0 => firstValue as u32,
27 ref unexpectedToken => {
28 return CustomParseError::unexpectedToken(unexpectedToken)
29 }
30 };
31
32 match input.next() {
33 Ok(&Token::Number {
34 int_value: Some(secondValue),
35 ..
36 }) if secondValue >= 0 => {
37 Ok(PairValues(first, Some(secondValue as u32)))
38 }
39
40 Ok(unexpectedToken) => {
42 CustomParseError::unexpectedToken(unexpectedToken)
43 }
44
45 Err(_) => Ok(PairValues(first, None)),
47 }
48 }
49}
50
51impl ToCss for PairValues {
52 fn to_css<W: fmt::Write>(&self, dest: &mut W) -> fmt::Result {
53 self.0.to_css(dest)?;
54
55 if let Some(second) = self.1 {
56 dest.write_char(' ')?;
57 second.to_css(dest)?;
58 }
59 Ok(())
60 }
61}