@@ -42,6 +42,45 @@ use std::{
42
42
path:: Path ,
43
43
str,
44
44
} ;
45
+ use thiserror:: Error ;
46
+
47
+ /// candump line parse error
48
+ #[ derive( Error , Debug ) ]
49
+ pub enum ParseError {
50
+ /// I/O Error
51
+ #[ error( transparent) ]
52
+ Io ( #[ from] io:: Error ) ,
53
+ /// Unexpected end of line
54
+ #[ error( "Unexpected end of line" ) ]
55
+ UnexpectedEndOfLine ,
56
+ /// Invalid time stamp
57
+ #[ error( "Invalid timestamp" ) ]
58
+ InvalidTimestamp ,
59
+ /// Invalid device name
60
+ #[ error( "Invalid device name" ) ]
61
+ InvalidDeviceName ,
62
+ /// Invalid CAN frame
63
+ #[ error( "Invalid CAN frame" ) ]
64
+ InvalidCanFrame ,
65
+ /// Error creating the frame
66
+ #[ error( transparent) ]
67
+ ConstructionError ( #[ from] ConstructionError ) ,
68
+ }
69
+
70
+ /// Recorded CAN frame.
71
+ /// This corresponds to the information in a line from the candump log.
72
+ #[ derive( Debug ) ]
73
+ pub struct CanDumpRecord < ' a > {
74
+ /// The timestamp
75
+ pub t_us : u64 ,
76
+ /// The name of the device
77
+ pub device : & ' a str ,
78
+ /// The parsed frame
79
+ pub frame : CanAnyFrame ,
80
+ }
81
+
82
+ /////////////////////////////////////////////////////////////////////////////
83
+ // Reader
45
84
46
85
#[ derive( Debug ) ]
47
86
/// A CAN log reader.
@@ -69,56 +108,10 @@ impl Reader<File> {
69
108
}
70
109
}
71
110
72
- /// Record iterator
73
- #[ derive( Debug ) ]
74
- pub struct CanDumpRecords < ' a , R : ' a > {
75
- src : & ' a mut Reader < R > ,
76
- }
77
-
78
- /// Recorded CAN frame.
79
- #[ derive( Debug ) ]
80
- pub struct CanDumpRecord < ' a > {
81
- /// The timestamp
82
- pub t_us : u64 ,
83
- /// The name of the device
84
- pub device : & ' a str ,
85
- /// The parsed frame
86
- pub frame : CanAnyFrame ,
87
- }
88
-
89
- #[ derive( Debug ) ]
90
- /// candump line parse error
91
- pub enum ParseError {
92
- /// I/O Error
93
- Io ( io:: Error ) ,
94
- /// Unexpected end of line
95
- UnexpectedEndOfLine ,
96
- /// Invalid time stamp
97
- InvalidTimestamp ,
98
- /// Invalid device name
99
- InvalidDeviceName ,
100
- /// Invalid CAN frame
101
- InvalidCanFrame ,
102
- /// Error creating the frame
103
- ConstructionError ( ConstructionError ) ,
104
- }
105
-
106
- impl From < io:: Error > for ParseError {
107
- fn from ( e : io:: Error ) ->ParseError {
108
- ParseError :: Io ( e)
109
- }
110
- }
111
-
112
- impl From < ConstructionError > for ParseError {
113
- fn from ( e : ConstructionError ) ->ParseError {
114
- ParseError :: ConstructionError ( e)
115
- }
116
- }
117
-
118
111
impl < R : BufRead > Reader < R > {
119
112
/// Returns an iterator over all records
120
- pub fn records ( & mut self ) ->CanDumpRecords < R > {
121
- CanDumpRecords { src : self }
113
+ pub fn records ( & mut self ) ->CanDumpIter < R > {
114
+ CanDumpIter { src : self }
122
115
}
123
116
124
117
/// Advance state, returning next record.
@@ -213,7 +206,13 @@ impl<R: BufRead> Reader<R> {
213
206
}
214
207
}
215
208
216
- impl < R : io:: Read > Iterator for CanDumpRecords < ' _ , BufReader < R > > {
209
+ /// Record iterator
210
+ #[ derive( Debug ) ]
211
+ pub struct CanDumpIter < ' a , R : ' a > {
212
+ src : & ' a mut Reader < R > ,
213
+ }
214
+
215
+ impl < R : io:: Read > Iterator for CanDumpIter < ' _ , BufReader < R > > {
217
216
type Item =Result < ( u64 , CanAnyFrame ) , ParseError > ;
218
217
219
218
fn next ( & mut self ) ->Option < Self :: Item > {
@@ -226,6 +225,12 @@ impl<R: io::Read> Iterator for CanDumpRecords<'_, BufReader<R>> {
226
225
}
227
226
}
228
227
228
+ // TODO: Remove in the next major version update
229
+ /// Obsolete iterator name, now called `CanDumpIter`
230
+ #[ allow( type_alias_bounds) ]
231
+ #[ deprecated( since="3.5.0" , note="Renamed to `CanDumpIter`" ) ]
232
+ pub type CanDumpRecords < ' a , R : ' a > =CanDumpIter < ' a , R > ;
233
+
229
234
/////////////////////////////////////////////////////////////////////////////
230
235
231
236
#[ cfg( test) ]