reactor_rt/time.rs
1/*
2 * Copyright (c) 2021, TU Dresden.
3 *
4 * Redistribution and use in source and binary forms, with or without modification,
5 * are permitted provided that the following conditions are met:
6 *
7 * 1. Redistributions of source code must retain the above copyright notice,
8 * this list of conditions and the following disclaimer.
9 *
10 * 2. Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
16 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
17 * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
18 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
21 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
22 * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 */
24
25use std::fmt::{Debug, Display, Formatter};
26use std::ops::Add;
27
28/// Private concrete type of a microstep.
29pub(crate) type MS = u32;
30
31/// Type of the microsteps of an [EventTag](crate::EventTag).
32#[derive(Debug, Eq, PartialEq, Ord, PartialOrd, Copy, Clone, Hash)]
33pub struct MicroStep(MS);
34
35impl MicroStep {
36 pub const ZERO: MicroStep = MicroStep(0);
37 pub fn new(u: MS) -> Self {
38 Self(u)
39 }
40}
41
42impl Display for MicroStep {
43 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
44 Display::fmt(&self.0, f)
45 }
46}
47
48impl Add<MS> for MicroStep {
49 type Output = Self;
50 #[inline]
51 fn add(self, rhs: MS) -> Self::Output {
52 Self(self.0 + rhs)
53 }
54}