rocket_http_community/uri/
error.rs

1//! Errors arising from parsing invalid URIs.
2
3use std::fmt;
4
5pub use crate::parse::uri::Error;
6
7/// The error type returned when a URI conversion fails.
8#[derive(Debug, Copy, Clone, PartialEq, Eq)]
9pub struct TryFromUriError(pub(crate) ());
10
11impl fmt::Display for TryFromUriError {
12    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
13        "invalid conversion from general to specific URI variant".fmt(f)
14    }
15}
16
17/// An error interpreting a segment as a [`PathBuf`] component in
18/// [`Segments::to_path_buf()`].
19///
20/// [`PathBuf`]: std::path::PathBuf
21/// [`Segments::to_path_buf()`]: crate::uri::Segments::to_path_buf()
22#[derive(Debug, PartialEq, Eq, Clone)]
23pub enum PathError {
24    /// The segment started with the wrapped invalid character.
25    BadStart(char),
26    /// The segment contained the wrapped invalid character.
27    BadChar(char),
28    /// The segment ended with the wrapped invalid character.
29    BadEnd(char),
30}
31
32impl fmt::Display for PathError {
33    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
34        match self {
35            PathError::BadStart(c) => write!(f, "invalid initial character: {c:?}"),
36            PathError::BadChar(c) => write!(f, "invalid character: {c:?}"),
37            PathError::BadEnd(c) => write!(f, "invalid terminal character: {c:?}"),
38        }
39    }
40}
41
42impl std::error::Error for PathError {}