use pct_str::{InvalidPctString, PctStr, PctString, URIReserved};
pub fn url_encode(s: &str) -> String {
let p = PctString::encode(s.chars(), URIReserved);
p.to_string()
}
#[derive(Debug, thiserror::Error)]
#[error("url decoding error: {0:#}")]
pub struct UrlDecodingError(Box<String>);
impl From<InvalidPctString<&str>> for UrlDecodingError {
fn from(e: InvalidPctString<&str>) -> Self {
Self(Box::new(format!("{}", e)))
}
}
pub fn url_decode(s: &str) -> Result<String, UrlDecodingError> {
let p = PctStr::new(s)?;
Ok(p.decode())
}