Newer
Older
use std::fmt::{Debug, Display};
#[derive(Eq, PartialEq, Hash, Debug)]
pub struct UrlPath {
parts: Vec<String>,
}
impl UrlPath {
pub fn new(s: &str) -> Self {
let parts = s
.split('/')
.filter(|x| !x.is_empty())
.map(|x| x.to_string())
.collect();
Self { parts }
}
}
impl Display for UrlPath {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.parts.join("/"))
}
}