Trait mz_ore::str::StrExt

source ·
pub trait StrExt {
    // Required method
    fn quoted(&self) -> QuotedStr<'_>;
}
Expand description

Extension methods for str.

Required Methods§

source

fn quoted(&self) -> QuotedStr<'_>

Wraps the string slice in a type whose display implementation renders the string surrounded by double quotes with any inner double quote characters escaped.

Examples

In the standard case, when the wrapped string does not contain any double quote characters:

use mz_ore::str::StrExt;

let name = "bob";
let message = format!("unknown user {}", name.quoted());
assert_eq!(message, r#"unknown user "bob""#);

In a pathological case:

use mz_ore::str::StrExt;

let name = r#"b@d"inp!t""#;
let message = format!("unknown user {}", name.quoted());
assert_eq!(message, r#"unknown user "b@d\"inp!t\"""#);

Implementations on Foreign Types§

source§

impl StrExt for str

source§

fn quoted(&self) -> QuotedStr<'_>

Implementors§