1use std::io;
2use std::num::ParseIntError;
3use std::string::FromUtf8Error;
4
5use substring::Substring;
6use thiserror::Error;
7
8pub type Result<T> = std::result::Result<T, Error>;
9
10#[derive(Debug, Error, PartialEq)]
11#[non_exhaustive]
12pub enum Error {
13    #[error("codec not found")]
14    CodecNotFound,
15    #[error("missing whitespace")]
16    MissingWhitespace,
17    #[error("missing colon")]
18    MissingColon,
19    #[error("payload type not found")]
20    PayloadTypeNotFound,
21    #[error("{0}")]
22    Io(#[source] IoError),
23    #[error("utf-8 error: {0}")]
24    Utf8(#[from] FromUtf8Error),
25    #[error("SdpInvalidSyntax: {0}")]
26    SdpInvalidSyntax(String),
27    #[error("SdpInvalidValue: {0}")]
28    SdpInvalidValue(String),
29    #[error("sdp: empty time_descriptions")]
30    SdpEmptyTimeDescription,
31    #[error("parse int: {0}")]
32    ParseInt(#[from] ParseIntError),
33    #[error("parse url: {0}")]
34    ParseUrl(#[from] url::ParseError),
35    #[error("parse extmap: {0}")]
36    ParseExtMap(String),
37    #[error("{} --> {} <-- {}", .s.substring(0,*.p), .s.substring(*.p, *.p+1), .s.substring(*.p+1, .s.len()))]
38    SyntaxError { s: String, p: usize },
39}
40
41#[derive(Debug, Error)]
42#[error("io error: {0}")]
43pub struct IoError(#[from] pub io::Error);
44
45impl PartialEq for IoError {
47    fn eq(&self, other: &Self) -> bool {
48        self.0.kind() == other.0.kind()
49    }
50}
51
52impl From<io::Error> for Error {
53    fn from(e: io::Error) -> Self {
54        Error::Io(IoError(e))
55    }
56}