Skip to content

Commit 1f895d9

Browse files
committed
Revert to earlier error conversion
1 parent 628626b commit 1f895d9

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/gen.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use mac_address::{get_mac_address, MacAddress};
1+
use mac_address::{get_mac_address, MacAddress, MacAddressError};
22
use thiserror::Error;
33

44
use crate::{id::Flake, seq::SeqGen};
@@ -36,10 +36,7 @@ impl FlakeGen {
3636
/// let id: Flake = gen.next().expect("No ID was generated");
3737
/// ```
3838
pub fn with_mac_addr() -> Result<FlakeGen, FlakeGenErr> {
39-
let mac_addr: MacAddress = match get_mac_address() {
40-
Ok(Some(addr)) => addr,
41-
_ => return Err(FlakeGenErr::NoMacAddr),
42-
};
39+
let mac_addr: MacAddress = get_mac_address()?.ok_or(FlakeGenErr::NoMacAddr)?;
4340
let mac_addr: u64 =
4441
mac_addr.bytes().iter().fold(0u64, |acc, value| (acc << 8) + (*value as u64));
4542

@@ -90,6 +87,12 @@ pub enum FlakeGenErr {
9087
NoMacAddr,
9188
}
9289

90+
impl From<MacAddressError> for FlakeGenErr {
91+
fn from(_: MacAddressError) -> Self {
92+
FlakeGenErr::NoMacAddr
93+
}
94+
}
95+
9396
/// A FlakeErr is an error that could happen when we try to generate an _identifier_ (`Flake`)
9497
#[derive(Debug, Error)]
9598
pub enum FlakeErr {

0 commit comments

Comments
 (0)