lewp_css/domain/at_rules/counter_style/
negative.rs

1use {
2    super::Symbol,
3    crate::{
4        parsers::{Parse, ParserContext},
5        CustomParseError,
6    },
7    cssparser::{ParseError, Parser, ToCss},
8    std::fmt,
9};
10
11// 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.
12// 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.
13
14/// <https://drafts.csswg.org/css-counter-styles/#counter-style-negative>
15#[derive(Clone, Debug)]
16pub struct Negative(pub Symbol, pub Option<Symbol>);
17
18impl ToCss for Negative {
19    fn to_css<W: fmt::Write>(&self, dest: &mut W) -> fmt::Result {
20        self.0.to_css(dest)?;
21        if let Some(ref symbol) = self.1 {
22            dest.write_char(' ')?;
23            symbol.to_css(dest)?;
24        }
25        Ok(())
26    }
27}
28
29impl Parse for Negative {
30    fn parse<'i, 't>(
31        context: &ParserContext,
32        input: &mut Parser<'i, 't>,
33    ) -> Result<Self, ParseError<'i, CustomParseError<'i>>> {
34        Ok(Negative(
35            Symbol::parse(context, input)?,
36            input.r#try(|input| Symbol::parse(context, input)).ok(),
37        ))
38    }
39}