//! Url
use crate::app_error_from;
use crate::tina::data::AppResult;
use std::borrow::Cow;
/// Url扩展
pub trait UrlExt {
/// Url转码
fn url_encode(&self) -> AppResult<Cow<str>>;
/// Url解码
fn url_decode(&self) -> AppResult<Cow<str>>;
}
impl<T> UrlExt for T
where
T: AsRef<str>,
{
fn url_encode(&self) -> AppResult<Cow<str>> {
Ok(urlencoding::encode(self.as_ref()))
}
fn url_decode(&self) -> AppResult<Cow<str>> {
urlencoding::decode(self.as_ref()).map_err(app_error_from!())
}
}