Trait uucore::display::Quotable [−][src]
pub trait Quotable {
fn quote(&self) -> Quoted<'_>;
fn maybe_quote(&self) -> Quoted<'_> { ... }
}
Expand description
An extension trait for displaying filenames to users.
Required methods
Returns an object that implements Display
for printing filenames with
proper quoting and escaping for the platform.
On Unix this corresponds to sh/bash syntax, on Windows Powershell syntax is used.
Examples
use std::path::Path;
use uucore::display::Quotable;
let path = Path::new("foo/bar.baz");
println!("Found file {}", path.quote()); // Prints "Found file 'foo/bar.baz'"
Provided methods
fn maybe_quote(&self) -> Quoted<'_>
fn maybe_quote(&self) -> Quoted<'_>
Like quote()
, but don’t actually add quotes unless necessary because of
whitespace or special characters.
Examples
use std::path::Path;
use uucore::display::Quotable;
use uucore::show_error;
let foo = Path::new("foo/bar.baz");
let bar = Path::new("foo bar");
show_error!("{}: Not found", foo.maybe_quote()); // Prints "util: foo/bar.baz: Not found"
show_error!("{}: Not found", bar.maybe_quote()); // Prints "util: 'foo bar': Not found"