use super::super::{context::*, url::*, util::*};
use std::{fmt, path::*};
#[derive(Clone, Debug)]
pub struct FileUrl {
pub path: PathBuf,
pub host: Option<String>,
pub query: Option<UrlQuery>,
pub fragment: Option<String>,
pub(crate) context: UrlContextRef,
}
impl FileUrl {
pub fn new(
context: &UrlContextRef,
path: PathBuf,
host: Option<String>,
query: Option<UrlQuery>,
fragment: Option<String>,
) -> Self {
Self { host, path, query, fragment, context: context.clone() }
}
pub fn new_with(&self, path: PathBuf) -> Self {
Self::new(&self.context, path, self.host.clone(), self.query.clone(), self.fragment.clone())
}
}
impl fmt::Display for FileUrl {
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
let host = self.host.as_ref().map_or("", |host| &host);
let query = url_query_string(&self.query);
let fragment = url_fragment_string(&self.fragment);
write!(formatter, "file://{}{}{}{}", host, self.path.display(), query, fragment)
}
}
impl Into<UrlRef> for FileUrl {
fn into(self) -> UrlRef {
Box::new(self)
}
}