impl for borrowed osstr

This commit is contained in:
Rowan 2025-07-09 13:47:37 -04:00
parent 8bdacb4105
commit a6f13837e1

View file

@ -1,13 +1,7 @@
use crate::{OsDisplay, OsStringFormatter};
macro_rules! impl_os_from_str {
macro_rules! impl_borrowed {
($type:ty) => {
impl $crate::OsDisplay for $type {
fn fmt_os(&self, f: &mut OsStringFormatter) -> std::fmt::Result {
f.write_str(&self.to_string())
}
}
impl $crate::OsDisplay for &$type {
fn fmt_os(&self, f: &mut OsStringFormatter) -> std::fmt::Result {
(*self).fmt_os(f)
@ -21,6 +15,17 @@ macro_rules! impl_os_from_str {
}
};
}
macro_rules! impl_os_from_str {
($type:ty) => {
impl $crate::OsDisplay for $type {
fn fmt_os(&self, f: &mut OsStringFormatter) -> std::fmt::Result {
f.write_str(&self.to_string())
}
}
impl_borrowed!($type);
};
}
impl_os_from_str!(bool);
@ -49,20 +54,28 @@ impl OsDisplay for std::ffi::OsString {
}
}
impl OsDisplay for &std::ffi::OsStr {
impl_borrowed!(std::ffi::OsString);
impl OsDisplay for std::ffi::OsStr {
fn fmt_os(&self, f: &mut OsStringFormatter) -> std::fmt::Result {
f.write_os_str(self)
}
}
impl_borrowed!(std::ffi::OsStr);
impl OsDisplay for std::path::Path {
fn fmt_os(&self, f: &mut OsStringFormatter) -> std::fmt::Result {
f.write_os_str(&self.as_os_str())
}
}
impl_borrowed!(std::path::Path);
impl OsDisplay for std::path::PathBuf {
fn fmt_os(&self, f: &mut OsStringFormatter) -> std::fmt::Result {
f.write_os_str(&self.as_os_str())
}
}
impl_borrowed!(std::path::PathBuf);