Trait ore::str::StrExt[][src]

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

Extension methods for str.

Required methods

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

Implementors