very basic rendering support
This commit is contained in:
parent
889dbbce5a
commit
4efbe0c44e
5 changed files with 198 additions and 11 deletions
30
src/time.rs
30
src/time.rs
|
@ -1,6 +1,7 @@
|
|||
use anyhow::bail;
|
||||
use std::{
|
||||
fmt::{self, Display, Write as _},
|
||||
ops::{Add, Sub},
|
||||
str::FromStr
|
||||
};
|
||||
|
||||
|
@ -82,6 +83,35 @@ pub struct Time {
|
|||
pub micros: u32
|
||||
}
|
||||
|
||||
impl Add for Time {
|
||||
type Output = Self;
|
||||
|
||||
fn add(self, rhs: Self) -> Self {
|
||||
let mut seconds = self.seconds + rhs.seconds;
|
||||
let mut micros = self.micros + rhs.micros;
|
||||
if micros >= 1_000_000 {
|
||||
seconds += 1;
|
||||
micros -= 1_000_000;
|
||||
}
|
||||
Self { seconds, micros }
|
||||
}
|
||||
}
|
||||
|
||||
impl Sub for Time {
|
||||
type Output = Self;
|
||||
|
||||
fn sub(mut self, rhs: Self) -> Self {
|
||||
if rhs.micros > self.micros {
|
||||
self.seconds -= 1;
|
||||
self.micros += 1_000_000;
|
||||
}
|
||||
Self {
|
||||
seconds: self.seconds - rhs.seconds,
|
||||
micros: self.micros - rhs.micros
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl FromStr for Time {
|
||||
type Err = anyhow::Error;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue