css_ast/units/
decibel.rs

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