Skip to main content

as_raw_string

Function as_raw_string 

Source
pub fn as_raw_string(s: &str) -> Option<String>
Expand description

Returns a raw string representation if the string contains quotes or backslashes. Otherwise returns None (caller should use regular quoting or bare string).

A string containing a NUL also returns None, even when it has a quote or a backslash: a raw string reproduces its content byte for byte, so it cannot carry the \0 escape and a NUL inside one would be written verbatim.

Raw strings avoid escaping by using r#'...'# syntax with enough # characters to ensure the closing delimiter is unambiguous.

Note: Nushell requires at least one # in raw strings (i.e., r#'...'# not r'...').