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#
.
Trait Implementations§
impl<B: Eq + Buffer> Eq for StringLit<B>
impl<B: Buffer> StructuralPartialEq for StringLit<B>
Auto Trait Implementations§
impl<B> Freeze for StringLit<B>where
B: Freeze,
impl<B> RefUnwindSafe for StringLit<B>where
B: RefUnwindSafe,
impl<B> Send for StringLit<B>where
B: Send,
impl<B> Sync for StringLit<B>where
B: Sync,
impl<B> Unpin for StringLit<B>where
B: Unpin,
impl<B> UnwindSafe for StringLit<B>where
B: UnwindSafe,
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)