Skip to main content

is/
error.rs

1use std::error::Error;
2use std::fmt;
3use std::io;
4
5/// Errors from the ICE agent.
6#[allow(missing_docs)]
7#[derive(Debug)]
8pub enum IceError {
9    BadCandidate(String),
10}
11
12impl fmt::Display for IceError {
13    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
14        match self {
15            IceError::BadCandidate(msg) => write!(f, "ICE bad candidate: {}", msg),
16        }
17    }
18}
19
20impl Error for IceError {}
21
22/// A STUN message could not be parsed or processed.
23#[derive(Debug)]
24pub enum StunError {
25    /// A STUN message could not be parsed.
26    Parse(String),
27
28    /// An IO error occurred while handling a STUN message.
29    Io(io::Error),
30}
31
32impl fmt::Display for StunError {
33    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
34        match self {
35            StunError::Parse(msg) => write!(f, "STUN parse error: {}", msg),
36            StunError::Io(err) => write!(f, "STUN io: {}", err),
37        }
38    }
39}
40
41impl Error for StunError {
42    fn source(&self) -> Option<&(dyn Error + 'static)> {
43        match self {
44            StunError::Io(err) => Some(err),
45            _ => None,
46        }
47    }
48}
49
50impl From<io::Error> for StunError {
51    fn from(err: io::Error) -> Self {
52        StunError::Io(err)
53    }
54}