Skip to content

Commit

Permalink
moar traits
Browse files Browse the repository at this point in the history
  • Loading branch information
Donald Ball committed Jan 29, 2023
1 parent f8272b5 commit e903f9c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
6 changes: 3 additions & 3 deletions rust/speed/src/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,11 @@ impl<'a> Connection<'a> {
}
0x81 => {
let numroads = self.reader.read_u8().await?;
let mut roads: BTreeSet<Road> = 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)),
}
Expand Down
8 changes: 5 additions & 3 deletions rust/speed/src/domain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Road>,
}

#[derive(Clone, Debug)]
pub struct Ticket {
pub plate: Plate,
pub road: Road,
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit e903f9c

Please sign in to comment.