Skip to main content

css_ast/units/
decibel.rs

1use super::prelude::*;
2
3#[node]
4#[derive(
5	IntoCursor, ToSpan, SemanticEq, Parse, Peek, ToCursors, Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash,
6)]
7#[cfg_attr(feature = "serde", derive(serde::Serialize), serde())]
8#[cfg_attr(feature = "visitable", derive(csskit_derives::Visitable), visit(self))]
9#[derive(csskit_derives::NodeWithMetadata)]
10#[metadata(node_kinds = Dimension)]
11pub struct Decibel(#[atom(CssAtomSet::Db)] T![Dimension]);
12
13impl From<Decibel> for f32 {
14	fn from(percentage: Decibel) -> Self {
15		percentage.0.into()
16	}
17}
18
19impl ToNumberValue for Decibel {
20	fn to_number_value(&self) -> Option<f32> {
21		Some((*self).into())
22	}
23}
24
25#[cfg(test)]
26mod tests {
27	use super::*;
28	use crate::CssAtomSet;
29	use css_parse::assert_parse;
30
31	#[test]
32	fn test_writes() {
33		assert_parse!(CssAtomSet::ATOMS, Decibel, "1db");
34	}
35}