1use std::fmt;
2
3use crate::checked_value::impl_checked_value;
4use crate::{InvalidCssNumber, UnitInterval, serialization::CssWriteTo};
5
6#[derive(Clone, Copy, Debug, PartialEq)]
8pub struct Opacity(UnitInterval);
9
10impl Opacity {
11 #[track_caller]
13 pub fn new(value: f64) -> Self {
14 Self(UnitInterval::new(value))
15 }
16
17 pub fn try_new(value: f64) -> Result<Self, InvalidCssNumber> {
19 UnitInterval::try_new(value).map(Self)
20 }
21}
22
23impl CssWriteTo for Opacity {
24 fn css_fmt<W: fmt::Write>(&self, w: &mut W) -> fmt::Result {
25 write!(w, "{}", self.0)
26 }
27}
28
29impl_checked_value!(Opacity);