@@ -16,8 +16,11 @@ use tracing::{error, info, warn};
1616
1717/// An Enum declaring the direction the cursor will fetch (important if the cursor is scrollable) #
1818/// and how far the cursor moves. Not Required to interact directly with
19- #[ derive( Debug , Clone , Copy , PartialEq , PartialOrd , Eq , Ord , Serialize , Deserialize , Hash ) ]
19+ #[ derive(
20+ Debug , Clone , Copy , PartialEq , PartialOrd , Eq , Ord , Serialize , Deserialize , Hash , Default ,
21+ ) ]
2022pub enum FetchDirection {
23+ #[ default]
2124 NEXT ,
2225 PRIOR ,
2326 FIRST ,
@@ -30,24 +33,18 @@ pub enum FetchDirection {
3033 BackwardAll ,
3134}
3235
33- impl Default for FetchDirection {
34- fn default ( ) -> Self {
35- Self :: NEXT
36- }
37- }
38-
3936impl std:: fmt:: Display for FetchDirection {
4037 fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
4138 match self {
4239 Self :: NEXT => write ! ( f, "NEXT" ) ,
4340 Self :: PRIOR => write ! ( f, "PRIOR" ) ,
4441 Self :: FIRST => write ! ( f, "FIRST" ) ,
4542 Self :: LAST => write ! ( f, "LAST" ) ,
46- Self :: ABSOLUTE ( n) => write ! ( f, "{} {}" , "ABSOLUTE ", n) ,
47- Self :: RELATIVE ( n) => write ! ( f, "{} {}" , "RELATIVE ", n) ,
48- Self :: FORWARD ( n) => write ! ( f, "{} {}" , "FORWARD ", n) ,
43+ Self :: ABSOLUTE ( n) => write ! ( f, "ABSOLUTE {}" , n) ,
44+ Self :: RELATIVE ( n) => write ! ( f, "RELATIVE {}" , n) ,
45+ Self :: FORWARD ( n) => write ! ( f, "FORWARD {}" , n) ,
4946 Self :: ForwardAll => write ! ( f, "FORWARD ALL" ) ,
50- Self :: BACKWARD ( n) => write ! ( f, "{} {}" , "BACKWARD ", n) ,
47+ Self :: BACKWARD ( n) => write ! ( f, "BACKWARD {}" , n) ,
5148 Self :: BackwardAll => write ! ( f, "BACKWARD ALL" ) ,
5249 }
5350 }
@@ -133,9 +130,12 @@ impl FetchDirection {
133130
134131/// An Enum declaring whether the cursor shall fetch entries or just move its position.
135132/// Not Required to interact directly with.
136- #[ derive( Debug , Clone , Copy , Ord , PartialOrd , Eq , PartialEq , Hash , Serialize , Deserialize ) ]
133+ #[ derive(
134+ Debug , Clone , Copy , Ord , PartialOrd , Eq , PartialEq , Hash , Serialize , Deserialize , Default ,
135+ ) ]
137136pub enum FetchCmd {
138137 Move ,
138+ #[ default]
139139 Fetch ,
140140}
141141
@@ -148,12 +148,6 @@ impl std::fmt::Display for FetchCmd {
148148 }
149149}
150150
151- impl Default for FetchCmd {
152- fn default ( ) -> Self {
153- Self :: Fetch
154- }
155- }
156-
157151impl ToSql for FetchCmd {
158152 fn to_sql ( & self ) -> String {
159153 format ! ( "{}" , self )
@@ -409,17 +403,13 @@ impl FetchStmt {
409403 }
410404}
411405
412- #[ derive( Debug , Clone , Copy , PartialEq , PartialOrd , Eq , Ord , Serialize , Deserialize ) ]
406+ #[ derive( Debug , Clone , Copy , PartialEq , PartialOrd , Eq , Ord , Serialize , Deserialize , Default ) ]
413407pub enum Sensitivity {
408+ #[ default]
414409 INSENSITIVE ,
415410 ASENSITIVE ,
416411 SENSITIVE ,
417412}
418- impl Default for Sensitivity {
419- fn default ( ) -> Self {
420- Self :: INSENSITIVE
421- }
422- }
423413
424414impl std:: fmt:: Display for Sensitivity {
425415 fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
@@ -435,7 +425,7 @@ impl ToSql for Sensitivity {
435425 fn to_sql ( & self ) -> String {
436426 match self {
437427 Self :: SENSITIVE => unimplemented ! ( "Postgres has no support for SENSITIVE Cursors. SENSITIVE is only implemented for compability with the SQL Standard" ) ,
438- sensitivity => format ! ( " {} " , sensitivity. to_string ( ) )
428+ sensitivity => format ! ( " {} " , sensitivity)
439429 }
440430 }
441431}
@@ -867,8 +857,8 @@ impl<T: Model> ToSql for DeclareCursor<T> {
867857 r#"DECLARE "{}" BINARY{}{}SCROLL CURSOR {} HOLD FOR {}"# ,
868858 self . name. escape( ) ,
869859 self . sensitivity. to_sql( ) ,
870- self . scroll. then ( || "" ) . unwrap_or ( "NO " ) ,
871- self . hold. then ( || "WITH" ) . unwrap_or ( "WITHOUT" ) ,
860+ if self . scroll { "" } else { "NO " } ,
861+ if self . hold { "WITH" } else { "WITHOUT" } ,
872862 self . query. to_sql( )
873863 )
874864 }
@@ -918,7 +908,7 @@ impl Clone for CursorData {
918908 fn clone ( & self ) -> Self {
919909 Self {
920910 meta : self . meta . clone ( ) ,
921- used : self . used . clone ( ) ,
911+ used : self . used ,
922912 position : AtomicI64 :: new ( self . position . load ( std:: sync:: atomic:: Ordering :: Relaxed ) ) ,
923913 fetched : AtomicI64 :: new ( self . fetched . load ( std:: sync:: atomic:: Ordering :: Relaxed ) ) ,
924914 }
@@ -978,7 +968,7 @@ impl Cursor for CursorData {
978968 fn fetched ( & self ) -> i64 {
979969 self . fetched . load ( std:: sync:: atomic:: Ordering :: Relaxed )
980970 }
981- fn update_used ( & mut self ) -> ( ) {
971+ fn update_used ( & mut self ) {
982972 self . used = Instant :: now ( ) ;
983973 }
984974 fn get_position_mut ( & mut self ) -> & mut AtomicI64 {
@@ -1178,13 +1168,13 @@ pub trait Cursor: Sync + Send {
11781168 /// The number of fetched Records by the Server
11791169 fn fetched ( & self ) -> i64 ;
11801170 /// Updates the Cursor Stats. Warps `update_position` `update_used` and `update_fetched`
1181- fn update ( & mut self , fd : FetchDirection , row_count : i64 ) -> ( ) {
1171+ fn update ( & mut self , fd : FetchDirection , row_count : i64 ) {
11821172 self . update_used ( ) ;
11831173 self . update_fetched ( row_count) ;
11841174 self . update_position ( fd. to_position_update ( & row_count) ) ;
11851175 }
11861176 /// Adjust the current Position of the Cursor
1187- fn update_position ( & mut self , fd : FetchDirection ) -> ( ) {
1177+ fn update_position ( & mut self , fd : FetchDirection ) {
11881178 use FetchDirection :: * ;
11891179 let order = std:: sync:: atomic:: Ordering :: Relaxed ;
11901180 let cur = self . get_position_mut ( ) ;
@@ -1202,7 +1192,7 @@ pub trait Cursor: Sync + Send {
12021192 } ;
12031193 }
12041194 /// Increase the number of fetched records
1205- fn update_fetched ( & mut self , count : i64 ) -> ( ) {
1195+ fn update_fetched ( & mut self , count : i64 ) {
12061196 self . get_fetched_mut ( )
12071197 . fetch_add ( count, std:: sync:: atomic:: Ordering :: Relaxed ) ;
12081198 }
0 commit comments