Skip to content

Commit

Permalink
Split lib and main source and add PathTimes
Browse files Browse the repository at this point in the history
  • Loading branch information
livingsilver94 committed Sep 13, 2023
1 parent 682a69a commit b85e33e
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,7 @@ clap = "4.4.2"
ion-rs = "0.18.1"
ion-schema = "0.9.1"
thiserror = "1.0.48"

[[bin]]
name = "usysconf"
path = "src/bin/usysconf/main.rs"
File renamed without changes.
1 change: 1 addition & 0 deletions src/main.rs → src/bin/usysconf/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// SPDX-License-Identifier: MPL-2.0

mod cli;
mod pathtimes;

fn main() -> Result<(), cli::Error> {
cli::process()
Expand Down
30 changes: 30 additions & 0 deletions src/bin/usysconf/pathtimes.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
use std::collections::HashMap;
use std::io::{Read, Write};

type Path = String;
type Mtime = i64;

#[derive(Default)]
pub struct PathTimes {
map: HashMap<Path, Mtime>,
}

impl PathTimes {
pub fn new(source: impl Read) -> Result<Self, bincode::Error> {
Ok(Self {
map: bincode::deserialize_from(source)?,
})
}

pub fn update(&mut self, path: Path, mtime: Mtime) {
self.map.insert(path, mtime);
}

pub fn get(&self, path: &Path) -> Option<Mtime> {
self.map.get(path).copied()
}

pub fn save(&mut self, writer: impl Write) -> Result<(), bincode::Error> {
bincode::serialize_into(writer, &self.map)
}
}

0 comments on commit b85e33e

Please sign in to comment.