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 moresource§impl<B: Buffer> Display for ByteStringLit<B>
impl<B: Buffer> Display for ByteStringLit<B>
source§impl<B: Buffer> From<ByteStringLit<B>> for Literal
impl<B: Buffer> From<ByteStringLit<B>> for Literal
source§fn from(l: ByteStringLit<B>) -> Self
fn from(l: ByteStringLit<B>) -> Self
source§impl<B: Buffer> From<ByteStringLit<B>> for Literal<B>
impl<B: Buffer> From<ByteStringLit<B>> for Literal<B>
source§fn from(src: ByteStringLit<B>) -> Self
fn from(src: ByteStringLit<B>) -> Self
impl<B: Eq + Buffer> Eq for ByteStringLit<B>
impl<B: Buffer> StructuralPartialEq for ByteStringLit<B>
Auto Trait Implementations§
impl<B> Freeze for ByteStringLit<B>where
B: Freeze,
impl<B> RefUnwindSafe for ByteStringLit<B>where
B: RefUnwindSafe,
impl<B> Send for ByteStringLit<B>where
B: Send,
impl<B> Sync for ByteStringLit<B>where
B: Sync,
impl<B> Unpin for ByteStringLit<B>where
B: Unpin,
impl<B> UnwindSafe for ByteStringLit<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
)