style/values/computed/
time.rs1use crate::derives::*;
8use crate::values::CSSFloat;
9use crate::Zero;
10use std::fmt::{self, Write};
11use style_traits::{CssWriter, ToCss};
12
13#[derive(Animate, Clone, Copy, Debug, MallocSizeOf, PartialEq, PartialOrd, ToResolvedValue)]
15#[cfg_attr(feature = "servo", derive(Deserialize, Serialize))]
16#[repr(C)]
17pub struct Time {
18 seconds: CSSFloat,
19}
20
21impl Time {
22 pub fn from_seconds(seconds: CSSFloat) -> Self {
24 Time { seconds }
25 }
26
27 #[inline]
29 pub fn seconds(&self) -> CSSFloat {
30 self.seconds
31 }
32}
33
34impl ToCss for Time {
35 fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
36 where
37 W: Write,
38 {
39 self.seconds().to_css(dest)?;
40 dest.write_char('s')
41 }
42}
43
44impl Zero for Time {
45 fn zero() -> Self {
46 Self::from_seconds(0.0)
47 }
48
49 fn is_zero(&self) -> bool {
50 self.seconds == 0.
51 }
52}