Skip to main content

lightningcss/rules/
position_try.rs

1//! The `@position-try` rule.
2
3use super::Location;
4use crate::declaration::DeclarationBlock;
5use crate::error::PrinterError;
6use crate::printer::Printer;
7use crate::traits::ToCss;
8use crate::values::ident::DashedIdent;
9#[cfg(feature = "visitor")]
10use crate::visitor::Visit;
11
12/// A [@position-try](https://drafts.csswg.org/css-anchor-position-1/#position-try) rule.
13#[derive(Debug, PartialEq, Clone)]
14#[cfg_attr(feature = "visitor", derive(Visit))]
15#[cfg_attr(feature = "into_owned", derive(static_self::IntoOwned))]
16#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
17#[cfg_attr(feature = "jsonschema", derive(schemars::JsonSchema))]
18pub struct PositionTryRule<'i> {
19  /// The name of the position-try fallback.
20  #[cfg_attr(feature = "serde", serde(borrow))]
21  pub name: DashedIdent<'i>,
22  /// Declarations in the `@position-try` rule.
23  pub declarations: DeclarationBlock<'i>,
24  /// The location of the rule in the source file.
25  #[cfg_attr(feature = "visitor", skip_visit)]
26  pub loc: Location,
27}
28
29impl<'i> ToCss for PositionTryRule<'i> {
30  fn to_css<W>(&self, dest: &mut Printer<W>) -> Result<(), PrinterError>
31  where
32    W: std::fmt::Write,
33  {
34    #[cfg(feature = "sourcemap")]
35    dest.add_mapping(self.loc);
36    dest.write_str("@position-try ")?;
37    self.name.to_css(dest)?;
38    self.declarations.to_css_block(dest)
39  }
40}