use std::ffi::{OsStr, OsString};
use crate::path::Path;
#[derive(Debug, PartialEq)]
pub struct PathBuf {
inner: std::path::PathBuf,
}
impl PathBuf {
pub fn new() -> PathBuf {
std::path::PathBuf::new().into()
}
pub fn as_path(&self) -> &Path {
self.inner.as_path().into()
}
pub fn push<P: AsRef<Path>>(&mut self, path: P) {
self.inner.push(path.as_ref())
}
pub fn pop(&mut self) -> bool {
self.inner.pop()
}
pub fn set_file_name<S: AsRef<OsStr>>(&mut self, file_name: S) {
self.inner.set_file_name(file_name)
}
pub fn set_extension<S: AsRef<OsStr>>(&mut self, extension: S) -> bool {
self.inner.set_extension(extension)
}
pub fn into_os_string(self) -> OsString {
self.inner.into_os_string()
}
pub fn into_boxed_path(self) -> Box<Path> {
let rw = Box::into_raw(self.inner.into_boxed_path()) as *mut Path;
unsafe { Box::from_raw(rw) }
}
}
impl std::ops::Deref for PathBuf {
type Target = Path;
fn deref(&self) -> &Path {
self.as_ref()
}
}
impl std::borrow::Borrow<Path> for PathBuf {
fn borrow(&self) -> &Path {
&**self
}
}
impl From<std::path::PathBuf> for PathBuf {
fn from(path: std::path::PathBuf) -> PathBuf {
PathBuf { inner: path }
}
}
impl Into<std::path::PathBuf> for PathBuf {
fn into(self) -> std::path::PathBuf {
self.inner.into()
}
}
impl From<OsString> for PathBuf {
fn from(path: OsString) -> PathBuf {
std::path::PathBuf::from(path).into()
}
}
impl From<&str> for PathBuf {
fn from(path: &str) -> PathBuf {
std::path::PathBuf::from(path).into()
}
}
impl AsRef<Path> for PathBuf {
fn as_ref(&self) -> &Path {
Path::new(&self.inner)
}
}
impl AsRef<std::path::Path> for PathBuf {
fn as_ref(&self) -> &std::path::Path {
self.inner.as_ref()
}
}