Trait OsStringTools

Source
pub trait OsStringTools {
    // Required methods
    fn replace(self, pat: impl Bytes, to: impl Bytes) -> OsString;
    fn escape_double_quote(self) -> OsString;
    fn escape_single_quote(self) -> OsString;
    fn trim_start(self, pat: impl Bytes) -> OsString;
    fn trim_end(self, pat: impl Bytes) -> OsString;
}
Expand description

Includes some of the methods of OsStrTools but they take the OsString by value and return it without modification if the specific search pattern isn’t found.

Allocation is also avoided by reusing parts of the old string when possible. As such, the methods here can be slightly faster and might be preferable in some cases.

Required Methods§

Source

fn replace(self, pat: impl Bytes, to: impl Bytes) -> OsString

Replace all matches with something else.

If no matches are found the returned string contains the whole original string.

Source

fn escape_double_quote(self) -> OsString

Replace double quote characters in the string with "\\\"" for safe handling over to a shell.

Source

fn escape_single_quote(self) -> OsString

Replace single quote characters in the string with "\\''" for safe handling over to a shell.

Source

fn trim_start(self, pat: impl Bytes) -> OsString

Remove all matches of the pattern until a different character is found.

Returns the rest.

Source

fn trim_end(self, pat: impl Bytes) -> OsString

Remove all matches of the pattern from the end until a different character is found.

Returns the rest.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl OsStringTools for OsString

Source§

fn replace(self, pat: impl Bytes, to: impl Bytes) -> OsString

Source§

fn escape_double_quote(self) -> OsString

Source§

fn escape_single_quote(self) -> OsString

Source§

fn trim_start(self, pat: impl Bytes) -> OsString

Source§

fn trim_end(self, pat: impl Bytes) -> OsString

Implementors§