Trait uucore::display::Quotable

source ·
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§

source

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§

source

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§

source§

impl Quotable for str

source§

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

source§

impl Quotable for OsStr

source§

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

source§

impl Quotable for Path

source§

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

Implementors§