Function shell_quote::sh::escape
source · [−]Expand description
Escape a string of bytes into a new Vec<u8>.
This will return one of the following:
- The string as-is, if no escaping is necessary.
- A quoted string containing ANSI-C-like escapes, like
'foo\nbar'.
See escape_into for a variant that extends an existing Vec instead of
allocating a new one.
The input argument is Into<OsString>, so you can pass in regular Rust
strings, PathBuf, and so on. For a regular Rust string it will be quoted
byte for byte.
Examples
assert_eq!(sh::escape("foobar"), b"foobar");
assert_eq!(sh::escape("foo bar"), b"'foo bar'");