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§
Sourcefn replace(self, pat: impl Bytes, to: impl Bytes) -> OsString
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.
Sourcefn escape_double_quote(self) -> OsString
fn escape_double_quote(self) -> OsString
Replace double quote characters in the string with "\\\""
for
safe handling over to a shell.
Sourcefn escape_single_quote(self) -> OsString
fn escape_single_quote(self) -> OsString
Replace single quote characters in the string with "\\''"
for
safe handling over to a shell.
Sourcefn trim_start(self, pat: impl Bytes) -> OsString
fn trim_start(self, pat: impl Bytes) -> OsString
Remove all matches of the pattern 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.