Skip to content

Commit

Permalink
Refactor paths to return expanded string
Browse files Browse the repository at this point in the history
  • Loading branch information
AdamIsrael committed Jan 1, 2024
1 parent 5171533 commit 0927427
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "ieee-registry"
description = "A Rust crate to cache the IEEE public registries as csv. "
version = "0.1.1"
version = "0.2.0"
edition = "2021"
homepage = "https://github.com/AdamIsrael/ieee-registry"
documentation = "https://github.com/AdamIsrael/ieee-registry"
Expand Down
4 changes: 2 additions & 2 deletions src/cid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ const CACHE: &str = "~/.local/share/ieee/cid.csv";
type BoxResult<T> = std::result::Result<T, Box<dyn std::error::Error>>;

/// Cache the Company ID (cid)
pub fn get_cid_path() -> BoxResult<&'static str> {
pub fn get_cid_path() -> BoxResult<String> {
utils::download(URL, CACHE)?;

Ok(CACHE)
Ok(utils::expand_path(CACHE))
}
4 changes: 2 additions & 2 deletions src/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ const CACHE: &str = "~/.local/share/ieee/eth.csv";
type BoxResult<T> = std::result::Result<T, Box<dyn std::error::Error>>;

/// Cache the EtherType™ (eth)
pub fn get_eth_path() -> BoxResult<&'static str> {
pub fn get_eth_path() -> BoxResult<String> {
utils::download(URL, CACHE)?;

Ok(CACHE)
Ok(utils::expand_path(CACHE))
}
4 changes: 2 additions & 2 deletions src/iab.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ const CACHE: &str = "~/.local/share/ieee/iab.csv";
type BoxResult<T> = std::result::Result<T, Box<dyn std::error::Error>>;

/// Cache the IAB assignments
pub fn get_iab_path() -> BoxResult<&'static str> {
pub fn get_iab_path() -> BoxResult<String> {
utils::download(URL, CACHE)?;

Ok(CACHE)
Ok(utils::expand_path(CACHE))
}
4 changes: 2 additions & 2 deletions src/mam.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ const CACHE: &str = "~/.local/share/ieee/mam.csv";
type BoxResult<T> = std::result::Result<T, Box<dyn std::error::Error>>;

/// Cache the MAC Address Block Medium (mam)
pub fn get_mam_path() -> BoxResult<&'static str> {
pub fn get_mam_path() -> BoxResult<String> {
utils::download(URL, CACHE)?;

Ok(CACHE)
Ok(utils::expand_path(CACHE))
}
4 changes: 2 additions & 2 deletions src/manid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ const CACHE: &str = "~/.local/share/ieee/man.csv";
type BoxResult<T> = std::result::Result<T, Box<dyn std::error::Error>>;

/// Cache the Manufacturer ID (man)
pub fn get_manid_path() -> BoxResult<&'static str> {
pub fn get_manid_path() -> BoxResult<String> {
utils::download(URL, CACHE)?;

Ok(CACHE)
Ok(utils::expand_path(CACHE))
}
4 changes: 2 additions & 2 deletions src/opid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ const CACHE: &str = "~/.local/share/ieee/opid.csv";
type BoxResult<T> = std::result::Result<T, Box<dyn std::error::Error>>;

/// Cache the Operator ID (opid)
pub fn get_opid_path() -> BoxResult<&'static str> {
pub fn get_opid_path() -> BoxResult<String> {
utils::download(URL, CACHE)?;

Ok(CACHE)
Ok(utils::expand_path(CACHE))
}
4 changes: 2 additions & 2 deletions src/oui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ const CACHE: &str = "~/.local/share/ieee/oui.csv";
type BoxResult<T> = std::result::Result<T, Box<dyn std::error::Error>>;

/// Cache the Mac Address Block Large (oui)
pub fn get_oui_path() -> BoxResult<&'static str> {
pub fn get_oui_path() -> BoxResult<String> {
utils::download(URL, CACHE)?;

Ok(CACHE)
Ok(utils::expand_path(CACHE))
}
4 changes: 2 additions & 2 deletions src/oui36.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ const CACHE: &str = "~/.local/share/ieee/oui36.csv";
type BoxResult<T> = std::result::Result<T, Box<dyn std::error::Error>>;

/// Cache the Mac Address Block Small (oui36)
pub fn get_oui36_path() -> BoxResult<&'static str> {
pub fn get_oui36_path() -> BoxResult<String> {
utils::download(URL, CACHE)?;

Ok(CACHE)
Ok(utils::expand_path(CACHE))
}
9 changes: 9 additions & 0 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@ use expanduser::expanduser;

const MAX_AGE: u64 = 86400 * 30;

/// Expand the static relative path to a full absolute path
pub fn expand_path(path: &str) -> String {
expanduser::expanduser(path)
.unwrap()
.to_str()
.unwrap()
.to_string()
}

/// Download the file to a specific destination
pub fn download(url: &str, destination: &str) -> BoxResult<()> {
let path = expanduser(destination)?;
Expand Down

0 comments on commit 0927427

Please sign in to comment.