File tree Expand file tree Collapse file tree 1 file changed +8
-5
lines changed
Expand file tree Collapse file tree 1 file changed +8
-5
lines changed Original file line number Diff line number Diff line change 1- use mac_address:: { get_mac_address, MacAddress } ;
1+ use mac_address:: { get_mac_address, MacAddress , MacAddressError } ;
22use thiserror:: Error ;
33
44use 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 ) ]
9598pub enum FlakeErr {
You can’t perform that action at this time.
0 commit comments