lewp_css/domain/at_rules/counter_style/
additive_tuple.rs1use {
2 super::Symbol,
3 crate::{
4 parsers::{
5 separators::{Comma, Separated},
6 Parse,
7 ParserContext,
8 },
9 CustomParseError,
10 },
11 cssparser::{ParseError, Parser, ToCss},
12 std::fmt,
13};
14
15#[derive(Clone, Debug)]
20pub struct AdditiveTuple {
21 pub weight: u32,
23
24 pub symbol: Symbol,
26}
27
28impl ToCss for AdditiveTuple {
29 fn to_css<W: fmt::Write>(&self, dest: &mut W) -> fmt::Result {
30 self.weight.to_css(dest)?;
31 dest.write_char(' ')?;
32 self.symbol.to_css(dest)
33 }
34}
35
36impl Separated for AdditiveTuple {
37 type Delimiter = Comma;
38}
39
40impl Parse for AdditiveTuple {
41 fn parse<'i, 't>(
42 context: &ParserContext,
43 input: &mut Parser<'i, 't>,
44 ) -> Result<Self, ParseError<'i, CustomParseError<'i>>> {
45 let symbol = input.r#try(|input| Symbol::parse(context, input));
46 let weight = input.expect_integer()?;
47 if weight < 0 {
48 return Err(ParseError::from(
49 CustomParseError::CounterStyleAdditiveTupleWeightCanNotBeNegative(weight),
50 ));
51 }
52 let symbol = symbol.or_else(|_| Symbol::parse(context, input))?;
53 Ok(Self {
54 weight: weight as u32,
55 symbol,
56 })
57 }
58}