very basic rendering support

This commit is contained in:
Dominic 2023-10-30 21:26:17 +01:00
parent 889dbbce5a
commit 4efbe0c44e
Signed by: msrd0
GPG key ID: DCC8C247452E98F9
5 changed files with 198 additions and 11 deletions

View file

@ -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;