pub struct ByteStringLit<B: Buffer> {
raw: B,
value: Option<Vec<u8>>,
num_hashes: Option<u32>,
start_suffix: usize,
}
Expand description
A byte string or raw byte string literal, e.g. b"hello"
or br#"abc"def"#
.
See the reference for more information.
Fields§
§raw: B
The raw input.
value: Option<Vec<u8>>
The string value (with all escaped unescaped), or None
if there were
no escapes. In the latter case, input
is the string value.
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> ByteStringLit<B>
impl<B: Buffer> ByteStringLit<B>
Sourcepub fn parse(input: B) -> Result<Self, ParseError>
pub fn parse(input: B) -> Result<Self, ParseError>
Parses the input as a (raw) byte string literal. Returns an error if the input is invalid or represents a different kind of literal.
Sourcepub fn value(&self) -> &[u8] ⓘ
pub fn value(&self) -> &[u8] ⓘ
Returns the string value this literal represents (where all escapes have been turned into their respective values).
Sourcepub fn into_value(self) -> B::ByteCow
pub fn into_value(self) -> B::ByteCow
Like value
but returns a potentially owned version of the value.
The return value is either Cow<'static, [u8]>
if B = String
, or
Cow<'a, [u8]>
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_byte_string(&self) -> bool
pub fn is_raw_byte_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#
.
Source§impl ByteStringLit<&str>
impl ByteStringLit<&str>
Sourcepub fn into_owned(self) -> ByteStringLit<String>
pub fn into_owned(self) -> ByteStringLit<String>
Makes a copy of the underlying buffer and returns the owned version of
Self
.
Trait Implementations§
Source§impl<B: Clone + Buffer> Clone for ByteStringLit<B>
impl<B: Clone + Buffer> Clone for ByteStringLit<B>
Source§fn clone(&self) -> ByteStringLit<B>
fn clone(&self) -> ByteStringLit<B>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more