Skip to main content

leptos_css/
time.rs

1use std::fmt;
2
3use crate::checked_value::impl_checked_value;
4use crate::{FiniteF64, serialization::CssWriteTo};
5
6/// CSS time values.
7#[derive(Clone, Copy, Debug, PartialEq)]
8#[non_exhaustive]
9pub enum CssTime {
10    /// Seconds.
11    S(FiniteF64),
12    /// Milliseconds.
13    Ms(FiniteF64),
14}
15
16impl CssWriteTo for CssTime {
17    fn css_fmt<W: fmt::Write>(&self, w: &mut W) -> fmt::Result {
18        match self {
19            Self::S(v) => write!(w, "{v}s"),
20            Self::Ms(v) => write!(w, "{v}ms"),
21        }
22    }
23}
24
25impl std::ops::Neg for CssTime {
26    type Output = Self;
27
28    fn neg(self) -> Self {
29        match self {
30            Self::S(v) => Self::S(-v),
31            Self::Ms(v) => Self::Ms(-v),
32        }
33    }
34}
35
36impl_checked_value!(CssTime);