Trait uucore::display::Quotable

pub trait Quotable {
    // Required method
    fn quote(&self) -> Quoted<'_>;

    // Provided method
    fn maybe_quote(&self) -> Quoted<'_> { ... }
}
Expand description

An extension trait to apply quoting to strings.

This is implemented on str, OsStr and Path.

For finer control, see the constructors on Quoted.

Required Methods§

fn quote(&self) -> Quoted<'_>

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<'_>

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"

Implementations on Foreign Types§

§

impl Quotable for OsStr

§

fn quote(&self) -> Quoted<'_>

§

impl Quotable for str

§

fn quote(&self) -> Quoted<'_>

§

impl Quotable for Path

§

fn quote(&self) -> Quoted<'_>

Implementors§