Skip to content

Commit

Permalink
Refactor library layout to simplify import
Browse files Browse the repository at this point in the history
Changed the path of the library modules so we can `use ieee_registry` instead of `use ieee_registry::ieee`.
  • Loading branch information
AdamIsrael committed Dec 31, 2023
1 parent de53c28 commit db7e94e
Show file tree
Hide file tree
Showing 13 changed files with 43 additions and 52 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,10 @@

[![Continuous integration](https://github.com/AdamIsrael/ieee-registry/actions/workflows/ci.yaml/badge.svg?branch=main)](https://github.com/AdamIsrael/ieee-registry/actions/workflows/ci.yaml)

Premise: To cache the IEEE Registries public listings to the users ~/.local directory in order to be used for lookup purposes.
The IEEE-Registry crate provides a locally cached copy of the IEEE Registration Authority's public listings in the current users `~/.local/share/ieee/` directory in order to be used for lookup purposes.


```rust
use ieee_registry::ieee::*;

```
File renamed without changes.
File renamed without changes.
File renamed without changes.
18 changes: 0 additions & 18 deletions src/ieee/mod.rs

This file was deleted.

32 changes: 17 additions & 15 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
pub mod ieee;
mod cid;
mod eth;
mod iab;
mod mam;
mod manid;
mod opid;
mod oui;
mod oui36;
mod utils;

pub fn add(left: usize, right: usize) -> usize {
left + right
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn it_works() {
let result = add(2, 2);
assert_eq!(result, 4);
}
}
pub use cid::get_cid_path;
pub use eth::get_eth_path;
pub use iab::get_iab_path;
pub use mam::get_mam_path;
pub use manid::get_manid_path;
pub use opid::get_opid_path;
pub use oui::get_oui_path;
pub use oui36::get_oui36_path;
24 changes: 12 additions & 12 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
/// A CLI interface to the ieee-registry library
///
///
use ieee_registry::ieee::*;
use expanduser::expanduser;

use ieee_registry::*;

fn main() {
println!("Caching file(s)...");
println!("\t{:?}", get_cid_path().unwrap());
println!("\t{:?}", get_eth_path().unwrap());
println!("\t{:?}", get_iab_path().unwrap());
println!("\t{:?}", get_mam_path().unwrap());
println!("\t{:?}", get_manid_path().unwrap());
println!("\t{:?}", get_opid_path().unwrap());
println!("\t{:?}", get_oui_path().unwrap());
println!("\t{:?}", get_oui36_path().unwrap());
println!("Caching IEEE registry file(s)...");
println!("✔ {}", expanduser(get_cid_path().unwrap()).unwrap().display());
println!("✔ {}", expanduser(get_eth_path().unwrap()).unwrap().display());
println!("✔ {}", expanduser(get_iab_path().unwrap()).unwrap().display());
println!("✔ {}", expanduser(get_mam_path().unwrap()).unwrap().display());
println!("✔ {}", expanduser(get_manid_path().unwrap()).unwrap().display());
println!("✔ {}", expanduser(get_opid_path().unwrap()).unwrap().display());
println!("✔ {}", expanduser(get_oui_path().unwrap()).unwrap().display());
println!("✔ {}", expanduser(get_oui36_path().unwrap()).unwrap().display());
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
13 changes: 7 additions & 6 deletions src/ieee/utils.rs → src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@ const MAX_AGE: u64 = 86400 * 30;

/// Download the file to a specific destination
pub fn download(url: &str, destination: &str) -> BoxResult<()> {
// If the file exists and is less than MAX_AGE, don't download it again
if metadata(destination).is_ok() {
let age = age(destination)?;
let path = expanduser(destination)?;

// Short-circuit if the file is already downloaded and less than MAX_AGE old
if let Ok(age) = age(path.clone().into_os_string().to_str().unwrap()) {
if age < MAX_AGE {
return Ok(());
}
}

// Download the file
match reqwest::blocking::get(url) {
Ok(response) => {
let path = expanduser(destination)?;

// make sure the path exists
create_dir_all(path.parent().unwrap())?;

Expand Down Expand Up @@ -66,7 +66,8 @@ mod tests {
let md = fs::metadata(tmp).unwrap();
assert_ne!(0, md.len());
}
Err(_) => {
Err(e) => {
println!("Error: {}", e);
assert!(false);
}
}
Expand Down

0 comments on commit db7e94e

Please sign in to comment.