File tree Expand file tree Collapse file tree 7 files changed +129
-2
lines changed Expand file tree Collapse file tree 7 files changed +129
-2
lines changed Original file line number Diff line number Diff line change @@ -23,8 +23,10 @@ pub enum LogDirError {
23
23
}
24
24
25
25
impl LogDir {
26
- pub fn new ( dir_path : PathBuf ) -> LogDir {
27
- LogDir { dir_path }
26
+ pub fn new ( dir_path : impl Into < PathBuf > ) -> LogDir {
27
+ LogDir {
28
+ dir_path : dir_path. into ( ) ,
29
+ }
28
30
}
29
31
30
32
pub fn path ( & self ) -> & Path {
Original file line number Diff line number Diff line change @@ -283,3 +283,4 @@ pub mod blocking;
283
283
#[ cfg( feature = "asynchronous" ) ]
284
284
#[ cfg_attr( docsrs, doc( cfg( feature = "asynchronous" ) ) ) ]
285
285
pub mod asynchronous;
286
+ mod models;
Original file line number Diff line number Diff line change
1
+ pub mod log_dir;
2
+ mod log_file;
Original file line number Diff line number Diff line change
1
+ use std:: borrow:: Cow ;
2
+ use std:: path:: { Path , PathBuf } ;
3
+
4
+ mod iter;
5
+ mod try_iter;
6
+
7
+ pub use iter:: Iter ;
8
+ use crate :: logs:: models:: log_dir:: try_iter:: TryIter ;
9
+
10
+ pub struct LogDir < ' a > {
11
+ path : Cow < ' a , Path > ,
12
+ }
13
+
14
+ impl < ' a > LogDir < ' a > {
15
+ pub fn new ( path : & ' a Path ) -> Self {
16
+ LogDir { path : Cow :: Borrowed ( path) }
17
+ }
18
+
19
+ pub fn iter ( & ' a self ) -> Iter < ' a > {
20
+ Iter { inner : self }
21
+ }
22
+
23
+ pub fn try_iter ( & ' a self ) -> TryIter < ' a > {
24
+ TryIter { inner : self }
25
+ }
26
+ }
27
+
28
+ #[ cfg( test) ]
29
+ mod tests {
30
+ use crate :: logs:: models:: log_dir:: LogDir ;
31
+
32
+ #[ test]
33
+ fn api_design ( ) {
34
+ let log_dir = LogDir :: new ( "./path" . as_ref ( ) ) ;
35
+
36
+ log_dir. iter ( ) ;
37
+ }
38
+ }
Original file line number Diff line number Diff line change
1
+ use crate :: logs:: models:: log_dir:: LogDir ;
2
+ use crate :: logs:: models:: log_file:: LogFile ;
3
+
4
+ pub struct Iter < ' a > {
5
+ pub ( crate ) inner : & ' a LogDir < ' a > ,
6
+ }
7
+
8
+ impl < ' a > Iterator for Iter < ' a > {
9
+ type Item = LogFile < ' a > ;
10
+
11
+ fn next ( & mut self ) -> Option < Self :: Item > {
12
+ todo ! ( )
13
+ }
14
+ }
Original file line number Diff line number Diff line change
1
+ use crate :: logs:: models:: log_file:: { LogFile , LogFileError } ;
2
+ use crate :: logs:: models:: log_dir:: LogDir ;
3
+
4
+ pub struct TryIter < ' a > {
5
+ pub ( crate ) inner : & ' a LogDir < ' a > ,
6
+ }
7
+
8
+ impl < ' a > TryIter < ' a > {
9
+ pub fn new ( inner : & ' a LogDir ) -> Self {
10
+ TryIter { inner }
11
+ }
12
+ }
13
+
14
+ impl < ' a > Iterator for TryIter < ' a > {
15
+ type Item = Result < LogFile < ' a > , LogFileError > ;
16
+
17
+ fn next ( & mut self ) -> Option < Self :: Item > {
18
+ let dir = self . inner
19
+ . path
20
+ . read_dir ( ) ;
21
+
22
+ let value = match dir {
23
+ Ok ( value) => value,
24
+ Err ( error) => return Some ( Err ( error. into ( ) ) ) ,
25
+ } ;
26
+ }
27
+ }
Original file line number Diff line number Diff line change
1
+ use std:: borrow:: Cow ;
2
+ use std:: fs:: DirEntry ;
3
+ use std:: path:: Path ;
4
+ use lazy_static:: lazy_static;
5
+ use regex:: Regex ;
6
+ use thiserror:: Error ;
7
+
8
+ pub struct LogFile < ' a > {
9
+ path : Cow < ' a , Path > ,
10
+ }
11
+
12
+ #[ derive( Debug , Error ) ]
13
+ #[ error( transparent) ]
14
+ pub enum LogFileError {
15
+ IO ( #[ from] std:: io:: Error ) ,
16
+ }
17
+
18
+ #[ cfg( not( feature = "legacy" ) ) ]
19
+ type RegexList = [ ( Regex , & ' static str ) ; 1 ] ;
20
+
21
+ #[ cfg( feature = "legacy" ) ]
22
+ type RegexList = [ ( Regex , & ' static str ) ; 2 ] ;
23
+
24
+ lazy_static ! {
25
+ static ref FILE_NAME_REGEXES : RegexList = [
26
+ // Journal.YYYY-MM-DDTHHmmss.01.log
27
+ ( Regex :: new( r"Journal\.(\d{4}-\d{2}-\d{2}T\d+)\.(\d{2})\.log" ) . unwrap( ) , "%Y-%m-%dT%H%M%S" ) ,
28
+
29
+ // Journal.YYMMDDHHMMSS.01.log
30
+ #[ cfg( feature = "legacy" ) ]
31
+ ( Regex :: new( r"Journal\.(\d{12})\.(\d{2})\.log" ) . unwrap( ) , "%y%m%d%H%M%S" ) ,
32
+ ] ;
33
+ }
34
+
35
+ impl < ' a > TryFrom < DirEntry > for LogFile < ' a > {
36
+ type Error = LogFileError ;
37
+
38
+ fn try_from ( value : DirEntry ) -> Result < Self , Self :: Error > {
39
+ let file_name = value. file_name ( ) ;
40
+
41
+ // let path = value.path();
42
+ }
43
+ }
You can’t perform that action at this time.
0 commit comments