1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
use std::fmt;
use std::num::{ParseIntError, ParseFloatError};
#[derive(Clone, Debug, PartialEq)]
pub enum ParseError {
UnsupportedSentenceType(String),
CorruptedSentence(String),
InvalidSentence(String),
}
impl From<String> for ParseError {
fn from(s: String) -> Self {
ParseError::InvalidSentence(s)
}
}
impl From<ParseIntError> for ParseError {
fn from(e: ParseIntError) -> Self {
ParseError::InvalidSentence(format!("{}", e))
}
}
impl From<ParseFloatError> for ParseError {
fn from(e: ParseFloatError) -> Self {
ParseError::InvalidSentence(format!("{}", e))
}
}
impl fmt::Display for ParseError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
ParseError::UnsupportedSentenceType(s) => {
write!(f, "Unsupported NMEA sentence type: {}", s)
}
ParseError::CorruptedSentence(s) => write!(f, "Corrupted NMEA sentence: {}", s),
ParseError::InvalidSentence(s) => write!(f, "Invalid NMEA sentence: {}", s),
}
}
}