Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit30f09bc

Browse files
committed
dump parsing errors now implement the std error trait
1 parentbed64af commit30f09bc

File tree

2 files changed

+55
-49
lines changed

2 files changed

+55
-49
lines changed

‎Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ neli = { version = "0.6", optional = true }
6464

6565
[dev-dependencies]
6666
anyhow ="1.0"
67+
clap ="3.2"
6768
ctrlc ="3.2.2"
6869
nb ="1.0"
6970
# TODO: Is it possible to only include these for async builds?

‎src/dump.rs

Lines changed: 54 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,45 @@ use std::{
4242
path::Path,
4343
str,
4444
};
45+
use thiserror::Error;
46+
47+
/// candump line parse error
48+
#[derive(Error,Debug)]
49+
pubenumParseError{
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+
pubstructCanDumpRecord<'a>{
74+
/// The timestamp
75+
pubt_us:u64,
76+
/// The name of the device
77+
pubdevice:&'astr,
78+
/// The parsed frame
79+
pubframe:CanAnyFrame,
80+
}
81+
82+
/////////////////////////////////////////////////////////////////////////////
83+
// Reader
4584

4685
#[derive(Debug)]
4786
/// A CAN log reader.
@@ -69,56 +108,10 @@ impl Reader<File> {
69108
}
70109
}
71110

72-
/// Record iterator
73-
#[derive(Debug)]
74-
pubstructCanDumpRecords<'a,R:'a>{
75-
src:&'amutReader<R>,
76-
}
77-
78-
/// Recorded CAN frame.
79-
#[derive(Debug)]
80-
pubstructCanDumpRecord<'a>{
81-
/// The timestamp
82-
pubt_us:u64,
83-
/// The name of the device
84-
pubdevice:&'astr,
85-
/// The parsed frame
86-
pubframe:CanAnyFrame,
87-
}
88-
89-
#[derive(Debug)]
90-
/// candump line parse error
91-
pubenumParseError{
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-
implFrom<io::Error>forParseError{
107-
fnfrom(e: io::Error) ->ParseError{
108-
ParseError::Io(e)
109-
}
110-
}
111-
112-
implFrom<ConstructionError>forParseError{
113-
fnfrom(e:ConstructionError) ->ParseError{
114-
ParseError::ConstructionError(e)
115-
}
116-
}
117-
118111
impl<R:BufRead>Reader<R>{
119112
/// Returns an iterator over all records
120-
pubfnrecords(&mutself) ->CanDumpRecords<R>{
121-
CanDumpRecords{src:self}
113+
pubfnrecords(&mutself) ->CanDumpIter<R>{
114+
CanDumpIter{src:self}
122115
}
123116

124117
/// Advance state, returning next record.
@@ -213,7 +206,13 @@ impl<R: BufRead> Reader<R> {
213206
}
214207
}
215208

216-
impl<R: io::Read>IteratorforCanDumpRecords<'_,BufReader<R>>{
209+
/// Record iterator
210+
#[derive(Debug)]
211+
pubstructCanDumpIter<'a,R:'a>{
212+
src:&'amutReader<R>,
213+
}
214+
215+
impl<R: io::Read>IteratorforCanDumpIter<'_,BufReader<R>>{
217216
typeItem =Result<(u64,CanAnyFrame),ParseError>;
218217

219218
fnnext(&mutself) ->Option<Self::Item>{
@@ -226,6 +225,12 @@ impl<R: io::Read> Iterator for CanDumpRecords<'_, BufReader<R>> {
226225
}
227226
}
228227

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+
pubtypeCanDumpRecords<'a,R:'a> =CanDumpIter<'a,R>;
233+
229234
/////////////////////////////////////////////////////////////////////////////
230235

231236
#[cfg(test)]

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp