1- use std:: fmt:: Debug ;
21use std:: marker:: PhantomData ;
32use std:: path:: Path ;
43use std:: result;
@@ -10,45 +9,6 @@ use serde::{Deserialize, Serialize};
109use thiserror:: Error ;
1110use wal:: { Wal , WalOptions } ;
1211
13- #[ derive( Error , Debug ) ]
14- #[ error( "{0}" ) ]
15- pub enum WalError {
16- #[ error( "Can't init WAL: {0}" ) ]
17- InitWalError ( String ) ,
18- #[ error( "Can't write WAL: {0}" ) ]
19- WriteWalError ( String ) ,
20- #[ error( "Can't truncate WAL: {0}" ) ]
21- TruncateWalError ( String ) ,
22- #[ error( "Operation rejected by WAL for old clock" ) ]
23- ClockRejected ,
24- }
25-
26- #[ derive( Debug , Deserialize , Serialize ) ]
27- #[ serde( rename_all = "snake_case" ) ]
28- struct TestInternalStruct1 {
29- data : usize ,
30- }
31-
32- #[ derive( Debug , Deserialize , Serialize ) ]
33- #[ serde( rename_all = "snake_case" ) ]
34- struct TestInternalStruct2 {
35- a : i32 ,
36- b : i32 ,
37- }
38-
39- pub type Result < T > = result:: Result < T , WalError > ;
40-
41- #[ derive( Debug , Deserialize , Serialize ) ]
42- struct WalState {
43- pub ack_index : u64 ,
44- }
45-
46- impl WalState {
47- pub fn new ( ack_index : u64 ) -> Self {
48- Self { ack_index }
49- }
50- }
51-
5212/// Write-Ahead-Log wrapper with built-in type parsing.
5313/// Stores sequences of records of type `R` in binary files.
5414///
@@ -57,16 +17,16 @@ impl WalState {
5717/// for removing old, no longer required, records.
5818#[ derive( Debug ) ]
5919pub struct SerdeWal < R > {
60- record : PhantomData < R > ,
6120 wal : Wal ,
6221 options : WalOptions ,
6322 /// First index of our logical WAL.
6423 first_index : Option < u64 > ,
24+ _record : PhantomData < R > ,
6525}
6626
6727const FIRST_INDEX_FILE : & str = "first-index" ;
6828
69- impl < R : DeserializeOwned + Serialize + Debug > SerdeWal < R > {
29+ impl < R : DeserializeOwned + Serialize > SerdeWal < R > {
7030 pub fn new ( dir : & str , wal_options : WalOptions ) -> Result < SerdeWal < R > > {
7131 let wal = Wal :: with_options ( dir, & wal_options)
7232 . map_err ( |err| WalError :: InitWalError ( format ! ( "{err:?}" ) ) ) ?;
@@ -88,10 +48,10 @@ impl<R: DeserializeOwned + Serialize + Debug> SerdeWal<R> {
8848 } ;
8949
9050 Ok ( SerdeWal {
91- record : PhantomData ,
9251 wal,
9352 options : wal_options,
9453 first_index,
54+ _record : PhantomData ,
9555 } )
9656 }
9757
@@ -252,6 +212,32 @@ impl<R: DeserializeOwned + Serialize + Debug> SerdeWal<R> {
252212 }
253213}
254214
215+ #[ derive( Debug , Deserialize , Serialize ) ]
216+ struct WalState {
217+ pub ack_index : u64 ,
218+ }
219+
220+ impl WalState {
221+ pub fn new ( ack_index : u64 ) -> Self {
222+ Self { ack_index }
223+ }
224+ }
225+
226+ pub type Result < T , E = WalError > = result:: Result < T , E > ;
227+
228+ #[ derive( Debug , Error ) ]
229+ #[ error( "{0}" ) ]
230+ pub enum WalError {
231+ #[ error( "Can't init WAL: {0}" ) ]
232+ InitWalError ( String ) ,
233+ #[ error( "Can't write WAL: {0}" ) ]
234+ WriteWalError ( String ) ,
235+ #[ error( "Can't truncate WAL: {0}" ) ]
236+ TruncateWalError ( String ) ,
237+ #[ error( "Operation rejected by WAL for old clock" ) ]
238+ ClockRejected ,
239+ }
240+
255241#[ cfg( test) ]
256242mod tests {
257243 #[ cfg( not( target_os = "windows" ) ) ]
@@ -272,6 +258,19 @@ mod tests {
272258 Struct2 ( TestInternalStruct2 ) ,
273259 }
274260
261+ #[ derive( Debug , Deserialize , Serialize ) ]
262+ #[ serde( rename_all = "snake_case" ) ]
263+ struct TestInternalStruct1 {
264+ data : usize ,
265+ }
266+
267+ #[ derive( Debug , Deserialize , Serialize ) ]
268+ #[ serde( rename_all = "snake_case" ) ]
269+ struct TestInternalStruct2 {
270+ a : i32 ,
271+ b : i32 ,
272+ }
273+
275274 #[ test]
276275 fn test_wal ( ) {
277276 let dir = Builder :: new ( ) . prefix ( "wal_test" ) . tempdir ( ) . unwrap ( ) ;
0 commit comments