pub trait Quotable {
fn quote(&self) -> Quoted<'_>;
fn maybe_quote(&self) -> Quoted<'_> { ... }
}
Expand description
Required Methods
Returns an object that implements Display
for printing strings with
proper quoting and escaping for the platform.
On Unix this corresponds to bash/ksh syntax, on Windows PowerShell syntax is used.
Examples
use std::path::Path;
use os_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 os_display::Quotable;
let foo = Path::new("foo/bar.baz");
let bar = "foo bar";
println!("{}: Not found", foo.maybe_quote()); // Prints "foo/bar.baz: Not found"
println!("{}: Not found", bar.maybe_quote()); // Prints "'foo bar': Not found"