From e903f9c5a235aa0ed52977a5501003efb9c4cab7 Mon Sep 17 00:00:00 2001 From: Donald Ball Date: Sun, 29 Jan 2023 15:10:45 -0500 Subject: [PATCH] moar traits --- rust/speed/src/connection.rs | 6 +++--- rust/speed/src/domain.rs | 8 +++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/rust/speed/src/connection.rs b/rust/speed/src/connection.rs index 0b78a52..2d7b1bc 100644 --- a/rust/speed/src/connection.rs +++ b/rust/speed/src/connection.rs @@ -84,11 +84,11 @@ impl<'a> Connection<'a> { } 0x81 => { let numroads = self.reader.read_u8().await?; - let mut roads: BTreeSet = BTreeSet::new(); + let mut dispatcher: Dispatcher = Default::default(); for _ in 0..numroads { - roads.insert(self.reader.read_u16().await?); + dispatcher.roads.insert(self.reader.read_u16().await?); } - Ok(Message::IAmDispatcher(Dispatcher { roads })) + Ok(Message::IAmDispatcher(dispatcher)) } _ => Err(io::Error::from(io::ErrorKind::Unsupported)), } diff --git a/rust/speed/src/domain.rs b/rust/speed/src/domain.rs index 753f295..727d720 100644 --- a/rust/speed/src/domain.rs +++ b/rust/speed/src/domain.rs @@ -41,17 +41,19 @@ pub type Speed = u16; pub type Plate = String; -#[derive(Clone, Copy)] +#[derive(Clone, Copy, Debug)] pub struct Camera { pub road: Road, pub mile: Mile, pub limit: Speed, } +#[derive(Clone, Debug, Default)] pub struct Dispatcher { pub roads: BTreeSet, } +#[derive(Clone, Debug)] pub struct Ticket { pub plate: Plate, pub road: Road, @@ -88,14 +90,14 @@ impl Region { let day1 = ticket.timestamp1 / 86400; let day2 = ticket.timestamp2 / 86400; let tickets_issued_days = self.tickets_issued_days.entry(plate).or_default(); - for day in day1..day2 + 1 { + for day in day1..=day2 { if tickets_issued_days.contains(&day) { return; } } let tickets_for_road = self.tickets_to_issue.entry(ticket.road).or_default(); tickets_for_road.push_back(ticket); - for day in day1..day2 + 1 { + for day in day1..=day2 { if tickets_issued_days.insert(day) { return; }