Trait uniquote::Quote

source ·
pub trait Quote {
    // Required method
    fn escape(&self, f: &mut Formatter<'_>) -> Result;

    // Provided method
    fn quote(&self) -> Display<&Self> { ... }
}
Expand description

The trait used to quote strings.

Required Methods§

source

fn escape(&self, f: &mut Formatter<'_>) -> Result

Escapes a string using the format described in the the module-level documentation, without the surrounding quotes.

This method is only used to provide new implementations of this trait.

Errors

Similarly to Display::fmt, this method should fail if and only if the formatter returns an error. Since quoting is an infallible operation, these failures will only result from inability to write to the underlying stream.

Examples
use uniquote::Quote;

struct Strings<'a>(&'a str, &'a str);

impl Quote for Strings<'_> {
    fn escape(&self, f: &mut uniquote::Formatter<'_>) -> uniquote::Result {
        self.0.escape(f)?;
        ','.escape(f)?;
        self.1.escape(f)
    }
}

assert_eq!(r#""foo,bar""#, Strings("foo", "bar").quote().to_string());

Provided Methods§

source

fn quote(&self) -> Display<&Self>

Quotes a string using the format described in the the module-level documentation.

The returned struct will implement Display. It can be output using a formatting macro or converted to a string by calling ToString::to_string.

Examples
use std::env;

use uniquote::Quote;

println!("{}", env::current_exe()?.quote());

Implementations on Foreign Types§

source§

impl Quote for char

source§

fn escape(&self, f: &mut Formatter<'_>) -> Result

source§

impl Quote for str

source§

fn escape(&self, f: &mut Formatter<'_>) -> Result

source§

impl Quote for [u8]

source§

fn escape(&self, f: &mut Formatter<'_>) -> Result

source§

impl<const N: usize> Quote for [u8; N]

source§

fn escape(&self, f: &mut Formatter<'_>) -> Result

source§

impl Quote for CStr

source§

fn escape(&self, f: &mut Formatter<'_>) -> Result

source§

impl Quote for CString

source§

fn escape(&self, f: &mut Formatter<'_>) -> Result

source§

impl Quote for String

source§

fn escape(&self, f: &mut Formatter<'_>) -> Result

source§

impl Quote for Vec<u8>

source§

fn escape(&self, f: &mut Formatter<'_>) -> Result

source§

impl Quote for OsStr

source§

fn escape(&self, f: &mut Formatter<'_>) -> Result

source§

impl Quote for Path

source§

fn escape(&self, f: &mut Formatter<'_>) -> Result

source§

impl Quote for OsString

source§

fn escape(&self, f: &mut Formatter<'_>) -> Result

source§

impl Quote for PathBuf

source§

fn escape(&self, f: &mut Formatter<'_>) -> Result

Implementors§