pub struct CStringLit<B: Buffer> {
raw: B,
value: CString,
num_hashes: Option<u8>,
start_suffix: usize,
}Expand description
A C string or raw C string literal, e.g. c"hello" or cr#"abc"def"#.
See the reference for more information.
Fields§
§raw: BThe raw input.
value: CStringThe string value (with all escaped unescaped) as CString. This is not an
Option as we always have to add the trailing zero byte.
num_hashes: Option<u8>The number of hash signs in case of a raw string literal, or None if
it’s not a raw string literal.
start_suffix: usizeStart index of the suffix or raw.len() if there is no suffix.
Implementations§
Source§impl<B: Buffer> CStringLit<B>
impl<B: Buffer> CStringLit<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) -> &CStr
pub fn value(&self) -> &CStr
Returns the string value this literal represents (where all escapes have been turned into their respective values).
Sourcepub fn into_value(self) -> CString
pub fn into_value(self) -> CString
Like value but returns an owned version of the value.
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_c_string(&self) -> bool
pub fn is_raw_c_string(&self) -> bool
Returns whether this literal is a raw string literal (starting with
cr).
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.
Source§impl CStringLit<&str>
impl CStringLit<&str>
Sourcepub fn into_owned(self) -> CStringLit<String>
pub fn into_owned(self) -> CStringLit<String>
Makes a copy of the underlying buffer and returns the owned version of
Self.
Trait Implementations§
Source§impl<B: Clone + Buffer> Clone for CStringLit<B>
impl<B: Clone + Buffer> Clone for CStringLit<B>
Source§fn clone(&self) -> CStringLit<B>
fn clone(&self) -> CStringLit<B>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more