From 5235cd58be2852bb496caee919ae6d203a0c6296 Mon Sep 17 00:00:00 2001 From: Wouter Geraedts Date: Sun, 13 Oct 2019 18:56:26 +0200 Subject: [PATCH] Implemented Path::display --- src/path/path.rs | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/path/path.rs b/src/path/path.rs index 6e76028..dcda43a 100644 --- a/src/path/path.rs +++ b/src/path/path.rs @@ -1,6 +1,6 @@ use std::ffi::OsStr; -use crate::path::{Ancestors, Components, PathBuf}; +use crate::path::{Ancestors, Components, Display, PathBuf}; use crate::{fs, io}; /// This struct is an async version of [`std::path::Path`]. @@ -106,6 +106,24 @@ impl Path { self.inner.components() } + /// Returns an object that implements [`Display`] for safely printing paths + /// that may contain non-Unicode data. + /// + /// [`Display`]: https://doc.rust-lang.org/std/fmt/trait.Display.html + /// + /// # Examples + /// + /// ``` + /// use async_std::path::Path; + /// + /// let path = Path::new("/tmp/foo.rs"); + /// + /// println!("{}", path.display()); + /// ``` + pub fn display(&self) -> Display<'_> { + self.inner.display() + } + /// Returns `true` if the path points at an existing entity. /// /// This function will traverse symbolic links to query information about the