mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-24 02:35:41 +00:00
14926dcf7c
<!-- Please describe your changes on the following line: --> Automatically verify that derive() lists are alphabetically ordered #18172 --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [X] These changes fix #18172 (github issue number if applicable). <!-- Either: --> - [X] There are tests for these changes OR - [ ] These changes do not require tests because _____ <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> Source-Repo: https://github.com/servo/servo Source-Revision: 474369618965569407d127b1e8c481e757cc59d3 --HG-- extra : subtree_source : https%3A//hg.mozilla.org/projects/converted-servo-linear extra : subtree_revision : 421aa68def8e17f70580477a4203494db3b69382
64 lines
1.8 KiB
Rust
64 lines
1.8 KiB
Rust
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
#![deny(missing_docs)]
|
|
|
|
//! A timer module, used to define a `Timer` type, that is controlled by script.
|
|
|
|
use time;
|
|
|
|
/// The `TimerMode` is used to determine what time should the `Timer` return.
|
|
#[derive(Clone, Debug)]
|
|
enum TimerMode {
|
|
/// The timer should return a fixed value.
|
|
Test(f64),
|
|
/// The timer should return the actual time.
|
|
Current,
|
|
}
|
|
|
|
/// A `Timer` struct that takes care of giving the current time for animations.
|
|
///
|
|
/// This is needed to be allowed to hook the time in the animations' test-mode.
|
|
#[derive(Clone, Debug)]
|
|
pub struct Timer {
|
|
mode: TimerMode,
|
|
}
|
|
|
|
impl Timer {
|
|
/// Creates a new "normal" timer, i.e., a "Current" mode timer.
|
|
#[inline]
|
|
pub fn new() -> Self {
|
|
Timer {
|
|
mode: TimerMode::Current,
|
|
}
|
|
}
|
|
|
|
/// Creates a new "test mode" timer, with initial time 0.
|
|
#[inline]
|
|
pub fn test_mode() -> Self {
|
|
Timer {
|
|
mode: TimerMode::Test(0.),
|
|
}
|
|
}
|
|
|
|
/// Returns the current time, at least from the caller's perspective. In
|
|
/// test mode returns whatever the value is.
|
|
pub fn seconds(&self) -> f64 {
|
|
match self.mode {
|
|
TimerMode::Test(test_value) => test_value,
|
|
TimerMode::Current => time::precise_time_s(),
|
|
}
|
|
}
|
|
|
|
/// Increments the current clock. Panics if the clock is not on test mode.
|
|
pub fn increment(&mut self, by: f64) {
|
|
match self.mode {
|
|
TimerMode::Test(ref mut val)
|
|
=> *val += by,
|
|
TimerMode::Current
|
|
=> panic!("Timer::increment called for a non-test mode timer. This is a bug."),
|
|
}
|
|
}
|
|
}
|