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))]
6pub struct Decibel(#[atom(CssAtomSet::Db)] T![Dimension]);
7
8impl From<Decibel> for f32 {
9	fn from(percentage: Decibel) -> Self {
10		percentage.0.into()
11	}
12}
13
14impl ToNumberValue for Decibel {
15	fn to_number_value(&self) -> Option<f32> {
16		Some((*self).into())
17	}
18}
19
20#[cfg(test)]
21mod tests {
22	use super::*;
23	use crate::CssAtomSet;
24	use css_parse::assert_parse;
25
26	#[test]
27	fn size_test() {
28		assert_eq!(std::mem::size_of::<Decibel>(), 12);
29	}
30
31	#[test]
32	fn test_writes() {
33		assert_parse!(CssAtomSet::ATOMS, Decibel, "1db");
34	}
35}