pub struct StringLit<B: Buffer> {
raw: B,
value: Option<String>,
num_hashes: Option<u32>,
start_suffix: usize,
}
Expand description
A string or raw string literal, e.g. "foo"
, "Grüße"
or r#"a🦊c"d🦀f"#
.
See the reference for more information.
Fields§
§raw: B
The raw input.
value: Option<String>
The string value (with all escapes unescaped), or None
if there were
no escapes. In the latter case, the string value is in raw
.
num_hashes: Option<u32>
The number of hash signs in case of a raw string literal, or None
if
it’s not a raw string literal.
start_suffix: usize
Start index of the suffix or raw.len()
if there is no suffix.
Implementations§
Source§impl<B: Buffer> StringLit<B>
impl<B: Buffer> StringLit<B>
Sourcepub fn parse(input: B) -> Result<Self, ParseError>
pub fn parse(input: B) -> Result<Self, ParseError>
Parses the input as a (raw) string literal. Returns an error if the input is invalid or represents a different kind of literal.
Sourcepub fn value(&self) -> &str
pub fn value(&self) -> &str
Returns the string value this literal represents (where all escapes have been turned into their respective values).
Sourcepub fn into_value(self) -> B::Cow
pub fn into_value(self) -> B::Cow
Like value
but returns a potentially owned version of the value.
The return value is either Cow<'static, str>
if B = String
, or
Cow<'a, str>
if B = &'a str
.
Sourcepub fn suffix(&self) -> &str
pub fn suffix(&self) -> &str
The optional suffix. Returns ""
if the suffix is empty/does not exist.
Sourcepub fn is_raw_string(&self) -> bool
pub fn is_raw_string(&self) -> bool
Returns whether this literal is a raw string literal (starting with
r
).
Sourcepub fn into_raw_input(self) -> B
pub fn into_raw_input(self) -> B
Returns the raw input that was passed to parse
, potentially owned.
Sourcefn inner_range(&self) -> Range<usize>
fn inner_range(&self) -> Range<usize>
The range within self.raw
that excludes the quotes and potential r#
.