lewp_css/domain/at_rules/media/
media_transform_3d.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},
10    std::fmt,
11};
12
13#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
14pub struct MediaTransform3D {
15    pub support: bool,
16}
17
18impl ToCss for MediaTransform3D {
19    fn to_css<W: fmt::Write>(&self, dest: &mut W) -> fmt::Result {
20        let value = if self.support { 1 } else { 0 };
21        value.to_css(dest)
22    }
23}
24
25impl Parse for MediaTransform3D {
26    fn parse<'i, 't>(
27        _context: &ParserContext,
28        input: &mut Parser<'i, 't>,
29    ) -> Result<Self, ParseError<'i, CustomParseError<'i>>> {
30        let support = match input.expect_integer()? {
31            0 => false,
32            1 => true,
33            invalid => {
34                return Err(ParseError::from(
35                    CustomParseError::MediaTransform3DMustBeEitherZeroOrOne(
36                        invalid,
37                    ),
38                ))
39            }
40        };
41
42        Ok(Self { support })
43    }
44}