11#![ doc = include_str ! ( "../README.md" ) ]
22// ^ if you are working on docs, go read the top comment of README.md please.
33
4- use core:: cell:: { LazyCell , OnceCell , RefCell } ;
4+ use core:: cell:: { Cell , LazyCell , OnceCell , RefCell } ;
55use core:: ops:: Deref ;
66use spacetimedb_lib:: bsatn;
77use std:: rc:: Rc ;
@@ -978,8 +978,9 @@ pub struct ReducerContext {
978978 #[ cfg( feature = "rand08" ) ]
979979 rng : std:: cell:: OnceCell < StdbRng > ,
980980 /// A counter used for generating UUIDv7 values.
981- /// **Note:** must be 0..=i32::MAX
982- counter_uuid : RefCell < i32 > ,
981+ /// **Note:** must be 0..=u32::MAX
982+ #[ cfg( feature = "rand" ) ]
983+ counter_uuid : Cell < u32 > ,
983984}
984985
985986impl ReducerContext {
@@ -993,7 +994,8 @@ impl ReducerContext {
993994 sender_auth : AuthCtx :: internal ( ) ,
994995 #[ cfg( feature = "rand08" ) ]
995996 rng : std:: cell:: OnceCell :: new ( ) ,
996- counter_uuid : RefCell :: new ( 0 ) ,
997+ #[ cfg( feature = "rand" ) ]
998+ counter_uuid : Cell :: new ( 0 ) ,
997999 }
9981000 }
9991001
@@ -1007,7 +1009,8 @@ impl ReducerContext {
10071009 sender_auth : AuthCtx :: from_connection_id_opt ( connection_id) ,
10081010 #[ cfg( feature = "rand08" ) ]
10091011 rng : std:: cell:: OnceCell :: new ( ) ,
1010- counter_uuid : RefCell :: new ( 0 ) ,
1012+ #[ cfg( feature = "rand" ) ]
1013+ counter_uuid : Cell :: new ( 0 ) ,
10111014 }
10121015 }
10131016
@@ -1073,6 +1076,7 @@ impl ReducerContext {
10731076 /// }
10741077 /// # }
10751078 /// ```
1079+ #[ cfg( feature = "rand" ) ]
10761080 pub fn new_uuid_v7 ( & self ) -> anyhow:: Result < Uuid > {
10771081 let mut random_bytes = [ 0u8 ; 4 ] ;
10781082 self . rng ( ) . try_fill_bytes ( & mut random_bytes) ?;
@@ -1138,8 +1142,10 @@ pub struct ProcedureContext {
11381142 #[ cfg( feature = "rand08" ) ]
11391143 rng : std:: cell:: OnceCell < StdbRng > ,
11401144 /// A counter used for generating UUIDv7 values.
1141- /// **Note:** must be 0..=i32::MAX
1142- counter_uuid : RefCell < i32 > ,
1145+ /// **Note:** must be 0..=u32::MAX
1146+ // Disabled when compiling without `rand`, as both v4 and v7 UUIDs have random components.
1147+ #[ cfg( feature = "rand" ) ]
1148+ counter_uuid : Cell < u32 > ,
11431149}
11441150
11451151#[ cfg( feature = "unstable" ) ]
@@ -1152,7 +1158,8 @@ impl ProcedureContext {
11521158 http : http:: HttpClient { } ,
11531159 #[ cfg( feature = "rand08" ) ]
11541160 rng : std:: cell:: OnceCell :: new ( ) ,
1155- counter_uuid : RefCell :: new ( 0 ) ,
1161+ #[ cfg( feature = "rand" ) ]
1162+ counter_uuid : Cell :: new ( 0 ) ,
11561163 }
11571164 }
11581165 /// Read the current module's [`Identity`].
@@ -1355,7 +1362,7 @@ impl ProcedureContext {
13551362 /// }
13561363 /// # }
13571364 /// ```
1358- #[ cfg( feature = "unstable" ) ]
1365+ #[ cfg( all ( feature = "unstable" , feature = "rand" ) ) ]
13591366 pub fn new_uuid_v7 ( & self ) -> anyhow:: Result < Uuid > {
13601367 let mut random_bytes = [ 0u8 ; 4 ] ;
13611368 self . rng ( ) . try_fill_bytes ( & mut random_bytes) ?;
0 commit comments