| 1 | use crate::{ |
| 2 | component::{Authority, Host, Scheme}, |
| 3 | parse::{ParseError, ParseErrorKind}, |
| 4 | pct_enc::{EStr, Encoder}, |
| 5 | ConvertError, |
| 6 | }; |
| 7 | use core::fmt::{Debug, Display, Formatter, Result}; |
| 8 | |
| 9 | impl<E: Encoder> Debug for EStr<E> { |
| 10 | fn fmt(&self, f: &mut Formatter<'_>) -> Result { |
| 11 | Debug::fmt(self.as_str(), f) |
| 12 | } |
| 13 | } |
| 14 | |
| 15 | impl<E: Encoder> Display for EStr<E> { |
| 16 | fn fmt(&self, f: &mut Formatter<'_>) -> Result { |
| 17 | Display::fmt(self.as_str(), f) |
| 18 | } |
| 19 | } |
| 20 | |
| 21 | impl Display for ParseError { |
| 22 | fn fmt(&self, f: &mut Formatter<'_>) -> Result { |
| 23 | let msg = match self.kind { |
| 24 | ParseErrorKind::InvalidPctEncodedOctet => "invalid percent-encoded octet at index ", |
| 25 | ParseErrorKind::UnexpectedChar => "unexpected character at index ", |
| 26 | ParseErrorKind::InvalidIpv6Addr => "invalid IPv6 address at index ", |
| 27 | }; |
| 28 | write!(f, "{}{}", msg, self.index) |
| 29 | } |
| 30 | } |
| 31 | |
| 32 | impl Display for ConvertError { |
| 33 | fn fmt(&self, f: &mut Formatter<'_>) -> Result { |
| 34 | match self { |
| 35 | Self::NotAscii { index } => write!(f, "non-ASCII character at index {index}"), |
| 36 | Self::NoScheme => f.write_str("scheme not present"), |
| 37 | } |
| 38 | } |
| 39 | } |
| 40 | |
| 41 | impl Debug for Scheme { |
| 42 | #[inline] |
| 43 | fn fmt(&self, f: &mut Formatter<'_>) -> Result { |
| 44 | Debug::fmt(self.as_str(), f) |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | impl Display for Scheme { |
| 49 | #[inline] |
| 50 | fn fmt(&self, f: &mut Formatter<'_>) -> Result { |
| 51 | Display::fmt(self.as_str(), f) |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | impl<RegNameE: Encoder> Debug for Host<'_, RegNameE> { |
| 56 | fn fmt(&self, f: &mut Formatter<'_>) -> Result { |
| 57 | match self { |
| 58 | #[cfg(feature = "net")] |
| 59 | Host::Ipv4(addr) => f.debug_tuple("Ipv4").field(addr).finish(), |
| 60 | #[cfg(feature = "net")] |
| 61 | Host::Ipv6(addr) => f.debug_tuple("Ipv6").field(addr).finish(), |
| 62 | |
| 63 | #[cfg(not(feature = "net"))] |
| 64 | Host::Ipv4() => f.debug_struct("Ipv4").finish_non_exhaustive(), |
| 65 | #[cfg(not(feature = "net"))] |
| 66 | Host::Ipv6() => f.debug_struct("Ipv6").finish_non_exhaustive(), |
| 67 | |
| 68 | Host::IpvFuture => f.debug_struct("IpvFuture").finish_non_exhaustive(), |
| 69 | Host::RegName(name) => f.debug_tuple("RegName").field(name).finish(), |
| 70 | } |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | impl<UserinfoE: Encoder, RegNameE: Encoder> Debug for Authority<'_, UserinfoE, RegNameE> { |
| 75 | fn fmt(&self, f: &mut Formatter<'_>) -> Result { |
| 76 | f.debug_struct("Authority") |
| 77 | .field("userinfo", &self.userinfo()) |
| 78 | .field("host", &self.host()) |
| 79 | .field("host_parsed", &self.host_parsed()) |
| 80 | .field("port", &self.port()) |
| 81 | .finish() |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | impl Display for Authority<'_> { |
| 86 | #[inline] |
| 87 | fn fmt(&self, f: &mut Formatter<'_>) -> Result { |
| 88 | Display::fmt(self.as_str(), f) |
| 89 | } |
| 90 | } |