Skip to main content

parse_duration

Function parse_duration 

Source
pub fn parse_duration(
    input: &str,
) -> Result<CssDuration, DurationParseError<'_>>
Expand description

Parses a CSS duration string (e.g. "200ms", "1.5s", "5t") into a CssDuration.

Three units are accepted:

  • ms — milliseconds
  • s — seconds (stored as milliseconds)
  • t — engine ticks / frames, kept as ticks (see CssDurationUnit::Ticks)

t is deliberately NOT normalised to milliseconds here: the whole reason the unit exists is that a tick count survives to the timer as an exact frame count, so a test can advance N ticks and assert the Nth frame — and only the Nth — flipped. Converting at parse time would throw that away and reintroduce the wall-clock rounding the unit is meant to escape.

§Errors

Returns an error if input is not a valid CSS duration value.