use std::ffi::OsString;
use std::path::Path;
use bstr::ByteSlice as _;
#[path="wtraits.rs"]
pub(crate) mod wtraits;
use wtraits::*;
#[path="funcs.rs"]
pub(crate) mod funcs;
pub use funcs::*;
use os_str_bytes::RawOsStr;
type Xstr = std::path::Path;
pub(crate) type WInput<'x> = Cow<'x, RawOsStr>;
pub(crate) type Wstr = RawOsStr;
pub(crate) type OString = OsString;
impl XstrRequirements for Path {
}
impl<P: AsRef<Path> + ?Sized> AsRefXstrExt for P {
fn into_winput(&self) -> Cow<'_, RawOsStr> { RawOsStr::new(self.as_ref().as_os_str()) }
fn into_ocow(&self) -> Cow<'_, Path> { self.as_ref().into() }
}
impl WstrExt for RawOsStr {
fn wstr_as_str(&self) -> Option<&str> { self.to_str() }
fn wstr_len(&self) -> usize {
self.rfind("").expect("empty string not found!")
}
fn wstr_to_ostring(&self) -> OsString { self.to_os_str().into_owned() }
fn wstr_strip_prefix(&self, c: char) -> Option<&Self> { self.strip_prefix(c) }
}
impl<'s> WstrRefExt for &'s RawOsStr {
type Chars = bstr::Chars<'s>;
#[allow(deprecated)]
fn wstr_chars_approx(self) -> bstr::Chars<'s> {
self.as_raw_bytes().chars()
}
}
impl CharsExt for bstr::Chars<'_> {
fn wstr_len(&self) -> usize {
self.as_bytes().len()
}
}
impl OStringExt for OsString {
fn push_str(&mut self, x: &str) { self.push(x) }
fn push_wstr(&mut self, x: &RawOsStr) { self.push(x.to_os_str()) }
fn push_xstr(&mut self, x: &Path) { self.push(x.as_os_str()) }
fn into_ocow(self) -> Cow<'static, Path> { PathBuf::from(self).into() }
fn display_possibly_lossy(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.write_str(&self.to_string_lossy())
}
}
impl PathBufExt for PathBuf {
fn try_into_xstring(self) -> Option<PathBuf> { Some(self) }
}