File tree Expand file tree Collapse file tree 4 files changed +15
-17
lines changed
Expand file tree Collapse file tree 4 files changed +15
-17
lines changed Original file line number Diff line number Diff line change @@ -13,15 +13,15 @@ pub mod event;
1313
1414pub ( crate ) static MIGRATIONS : sqlx:: migrate:: Migrator = sqlx:: migrate!( "./migrations" ) ;
1515
16+ use std:: sync:: LazyLock ;
17+
1618use eventually:: version:: { ConflictError , Version } ;
17- use lazy_static:: lazy_static;
1819use regex:: Regex ;
1920
20- lazy_static ! {
21- static ref CONFLICT_ERROR_REGEX : Regex =
22- Regex :: new( r"version check failed, expected: (?P<expected>\d), got: (?P<got>\d)" )
23- . expect( "regex compiles successfully" ) ;
24- }
21+ static CONFLICT_ERROR_REGEX : LazyLock < Regex > = LazyLock :: new ( || {
22+ Regex :: new ( r"version check failed, expected: (?P<expected>\d), got: (?P<got>\d)" )
23+ . expect ( "regex compiles successfully" )
24+ } ) ;
2525
2626pub ( crate ) fn check_for_conflict_error ( err : & sqlx:: Error ) -> Option < ConflictError > {
2727 fn capture_to_version ( captures : & regex:: Captures , name : & ' static str ) -> Version {
Original file line number Diff line number Diff line change @@ -343,8 +343,9 @@ where
343343#[ allow( clippy:: semicolon_if_nothing_returned) ] // False positives :shrugs:
344344#[ cfg( test) ]
345345mod test {
346+ use std:: sync:: LazyLock ;
347+
346348 use futures:: TryStreamExt ;
347- use lazy_static:: lazy_static;
348349
349350 use super :: * ;
350351 use crate :: event;
@@ -354,13 +355,13 @@ mod test {
354355
355356 const STREAM_ID : & str = "stream:test" ;
356357
357- lazy_static ! {
358- static ref EVENTS : Vec <event :: Envelope < StringMessage >> = vec![
358+ static EVENTS : LazyLock < Vec < event :: Envelope < StringMessage > > > = LazyLock :: new ( || {
359+ vec ! [
359360 event:: Envelope :: from( StringMessage ( "event-1" ) ) ,
360361 event:: Envelope :: from( StringMessage ( "event-2" ) ) ,
361362 event:: Envelope :: from( StringMessage ( "event-3" ) ) ,
362- ] ;
363- }
363+ ]
364+ } ) ;
364365
365366 #[ tokio:: test]
366367 async fn it_works ( ) {
Load Diff This file was deleted.
Original file line number Diff line number Diff line change @@ -59,7 +59,7 @@ impl Message for BankAccountEvent {
5959 BankAccountEvent :: TransferWasReceived { .. } => "BankAccountTransferWasReceived" ,
6060 BankAccountEvent :: TransferWasDeclined { .. } => "BankAccountTransferWasDeclined" ,
6161 BankAccountEvent :: TransferWasConfirmed { .. } => "BankAccountTransferWasConfirmed" ,
62- BankAccountEvent :: WasClosed { .. } => "BankAccountWasClosed" ,
62+ BankAccountEvent :: WasClosed => "BankAccountWasClosed" ,
6363 BankAccountEvent :: WasReopened { .. } => "BankAccountWasReopened" ,
6464 }
6565 }
@@ -233,7 +233,7 @@ impl BankAccountRoot {
233233 return Err ( BankAccountError :: InsufficientFunds ) ;
234234 }
235235
236- let transaction_already_pending = self . pending_transactions . get ( & transaction. id ) . is_some ( ) ;
236+ let transaction_already_pending = self . pending_transactions . contains_key ( & transaction. id ) ;
237237 if transaction_already_pending {
238238 return Ok ( ( ) ) ;
239239 }
@@ -275,7 +275,7 @@ impl BankAccountRoot {
275275 & mut self ,
276276 transaction_id : TransactionId ,
277277 ) -> Result < ( ) , BankAccountError > {
278- let is_transaction_recorded = self . pending_transactions . get ( & transaction_id) . is_some ( ) ;
278+ let is_transaction_recorded = self . pending_transactions . contains_key ( & transaction_id) ;
279279 if !is_transaction_recorded {
280280 // TODO: return error
281281 }
You can’t perform that action at this time.
0 commit comments