lewp_css/domain/at_rules/font_feature_values/
single_value.rs

1// This file is part of css. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/css/master/COPYRIGHT. No part of predicator, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2// Copyright © 2017 The developers of css. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/css/master/COPYRIGHT.
3
4use {
5    crate::{
6        parsers::{Parse, ParserContext},
7        CustomParseError,
8    },
9    cssparser::{ParseError, Parser, ToCss, Token},
10    std::fmt,
11};
12
13/// A @font-feature-values block declaration value that keeps one value.
14#[derive(Clone, Debug, PartialEq)]
15pub struct SingleValue(pub u32);
16
17impl Parse for SingleValue {
18    fn parse<'i, 't>(
19        _context: &ParserContext,
20        input: &mut Parser<'i, 't>,
21    ) -> Result<SingleValue, ParseError<'i, CustomParseError<'i>>> {
22        match *input.next()? {
23            Token::Number {
24                int_value: Some(value),
25                ..
26            } if value >= 0 => Ok(SingleValue(value as u32)),
27            ref unexpectedToken => {
28                CustomParseError::unexpectedToken(unexpectedToken)
29            }
30        }
31    }
32}
33
34impl ToCss for SingleValue {
35    fn to_css<W: fmt::Write>(&self, dest: &mut W) -> fmt::Result {
36        self.0.to_css(dest)
37    }
38}