@@ -5,33 +5,19 @@ mod _uuid {
55 use crate :: { builtins:: PyNone , vm:: VirtualMachine } ;
66 use mac_address:: get_mac_address;
77 use once_cell:: sync:: OnceCell ;
8- use rand:: Rng ;
9- use std:: time:: { Duration , SystemTime } ;
10- use uuid:: {
11- v1:: { Context , Timestamp } ,
12- Uuid ,
13- } ;
8+ use uuid:: { timestamp:: Timestamp , Context , Uuid } ;
149
1510 fn get_node_id ( ) -> [ u8 ; 6 ] {
1611 match get_mac_address ( ) {
1712 Ok ( Some ( _ma) ) => get_mac_address ( ) . unwrap ( ) . unwrap ( ) . bytes ( ) ,
18- _ => rand:: thread_rng ( ) . gen :: < [ u8 ; 6 ] > ( ) ,
13+ _ => rand:: random :: < [ u8 ; 6 ] > ( ) ,
1914 }
2015 }
2116
22- pub fn now_unix_duration ( ) -> Duration {
23- use std:: time:: UNIX_EPOCH ;
24-
25- let now = SystemTime :: now ( ) ;
26- now. duration_since ( UNIX_EPOCH )
27- . expect ( "SystemTime before UNIX EPOCH!" )
28- }
29-
3017 #[ pyfunction]
3118 fn generate_time_safe ( ) -> ( Vec < u8 > , PyNone ) {
3219 static CONTEXT : Context = Context :: new ( 0 ) ;
33- let now = now_unix_duration ( ) ;
34- let ts = Timestamp :: from_unix ( & CONTEXT , now. as_secs ( ) , now. subsec_nanos ( ) ) ;
20+ let ts = Timestamp :: now ( & CONTEXT ) ;
3521
3622 static NODE_ID : OnceCell < [ u8 ; 6 ] > = OnceCell :: new ( ) ;
3723 let unique_node_id = NODE_ID . get_or_init ( get_node_id) ;
0 commit comments