use std::fmt;
use std_prelude::*;
use super::{PathArc, PathDir, PathFile, Result};
#[derive(Clone, Eq, Hash, PartialEq, PartialOrd, Ord)]
pub struct PathAbs(pub(crate) PathArc);
impl PathAbs {
pub fn new<P: AsRef<Path>>(path: P) -> Result<PathAbs> {
let arc = PathArc::new(path);
arc.absolute()
}
pub fn into_file(self) -> Result<PathFile> {
PathFile::from_abs(self)
}
pub fn into_dir(self) -> Result<PathDir> {
PathDir::from_abs(self)
}
pub fn parent_dir(&self) -> Option<PathDir> {
match self.parent() {
Some(p) => Some(PathDir(PathAbs(PathArc::new(p)))),
None => None,
}
}
pub fn as_path(&self) -> &Path {
self.as_ref()
}
pub fn mock<P: AsRef<Path>>(fake_path: P) -> PathAbs {
PathAbs(PathArc::new(fake_path))
}
}
impl fmt::Debug for PathAbs {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
self.0.fmt(f)
}
}
impl AsRef<PathArc> for PathAbs {
fn as_ref(&self) -> &PathArc {
&self.0
}
}
impl AsRef<Path> for PathAbs {
fn as_ref(&self) -> &Path {
self.0.as_ref()
}
}
impl AsRef<PathBuf> for PathAbs {
fn as_ref(&self) -> &PathBuf {
self.0.as_ref()
}
}
impl Borrow<PathArc> for PathAbs {
fn borrow(&self) -> &PathArc {
self.as_ref()
}
}
impl Borrow<Path> for PathAbs {
fn borrow(&self) -> &Path {
self.as_ref()
}
}
impl Borrow<PathBuf> for PathAbs {
fn borrow(&self) -> &PathBuf {
self.as_ref()
}
}
impl<'a> Borrow<PathArc> for &'a PathAbs {
fn borrow(&self) -> &PathArc {
self.as_ref()
}
}
impl<'a> Borrow<Path> for &'a PathAbs {
fn borrow(&self) -> &Path {
self.as_ref()
}
}
impl<'a> Borrow<PathBuf> for &'a PathAbs {
fn borrow(&self) -> &PathBuf {
self.as_ref()
}
}
impl Deref for PathAbs {
type Target = PathArc;
fn deref(&self) -> &PathArc {
&self.0
}
}
impl Into<PathArc> for PathAbs {
fn into(self) -> PathArc {
self.0
}
}