Add display
method to OsStr
Add `display` method to `OsStr` for lossy display of an `OsStr` which may contain invalid unicode. Invalid Unicode sequences are replaced with `U+FFFD REPLACEMENT CHARACTER`. This change also makes the `std::ffi::os_str` module public.
This commit is contained in:
parent
8424f8e8cd
commit
a0fcc8ebc0
4 changed files with 73 additions and 10 deletions
|
@ -84,7 +84,7 @@ use crate::rc::Rc;
|
|||
use crate::str::FromStr;
|
||||
use crate::sync::Arc;
|
||||
|
||||
use crate::ffi::{OsStr, OsString};
|
||||
use crate::ffi::{os_str, OsStr, OsString};
|
||||
use crate::sys;
|
||||
use crate::sys::path::{is_sep_byte, is_verbatim_sep, parse_prefix, MAIN_SEP_STR};
|
||||
|
||||
|
@ -2725,7 +2725,7 @@ impl Path {
|
|||
it returns an object that can be displayed"]
|
||||
#[inline]
|
||||
pub fn display(&self) -> Display<'_> {
|
||||
Display { path: self }
|
||||
Display { inner: self.inner.display() }
|
||||
}
|
||||
|
||||
/// Queries the file system to get information about a file, directory, etc.
|
||||
|
@ -3032,20 +3032,20 @@ impl fmt::Debug for Path {
|
|||
/// [`format!`]: crate::format
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub struct Display<'a> {
|
||||
path: &'a Path,
|
||||
inner: os_str::Display<'a>,
|
||||
}
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl fmt::Debug for Display<'_> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
fmt::Debug::fmt(&self.path, f)
|
||||
fmt::Debug::fmt(&self.inner, f)
|
||||
}
|
||||
}
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl fmt::Display for Display<'_> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
self.path.inner.display(f)
|
||||
fmt::Display::fmt(&self.inner, f)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue