Skip to main content

pct_str/
error.rs

1use core::fmt::{self, Display, Formatter};
2
3/// Encoding error.
4///
5/// Raised when a given input string is not percent-encoded as expected.
6#[derive(Debug, Clone, Copy)]
7pub struct InvalidPctString<T>(pub T);
8
9impl<T> Display for InvalidPctString<T> {
10	fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
11		f.write_str("invalid percent-encoded string")
12	}
13}
14
15impl<T> InvalidPctString<T> {
16	pub fn map<U>(self, f: impl FnOnce(T) -> U) -> InvalidPctString<U> {
17		InvalidPctString(f(self.0))
18	}
19}
20
21#[cfg(feature = "std")]
22impl<T: ?Sized + ToOwned> InvalidPctString<&T> {
23	pub fn into_owned(self) -> InvalidPctString<T::Owned> {
24		self.map(T::to_owned)
25	}
26}