/// A (single) byte literal, e.g. `b'k'` or `b'!'`. /// /// See [the reference][ref] for more information. /// /// [ref]: https://doc.rust-lang.org/reference/tokens.html#byte-literals #[derive(Debug, Clone, Copy, PartialEq, Eq)] pubstruct ByteLit<B: Buffer> {
raw: B, /// Start index of the suffix or `raw.len()` if there is no suffix.
start_suffix: usize,
value: u8,
}
impl<B: Buffer> ByteLit<B> { /// Parses the input as a byte literal. Returns an error if the input is /// invalid or represents a different kind of literal. pubfn parse(input: B) -> Result<Self, ParseError> { if input.is_empty() { return Err(perr(None, Empty));
} if !input.starts_with("b'") { return Err(perr(None, InvalidByteLiteralStart));
}
/// Returns the byte value that this literal represents. pubfn value(&self) -> u8 { self.value
}
/// The optional suffix. Returns `""` if the suffix is empty/does not exist. pubfn suffix(&self) -> &str {
&(*self.raw)[self.start_suffix..]
}
/// Returns the raw input that was passed to `parse`. pubfn raw_input(&self) -> &str {
&self.raw
}
/// Returns the raw input that was passed to `parse`, potentially owned. pubfn into_raw_input(self) -> B { self.raw
}
}
impl ByteLit<&str> { /// Makes a copy of the underlying buffer and returns the owned version of /// `Self`. pubfn to_owned(&self) -> ByteLit<String> {
ByteLit {
raw: self.raw.to_owned(),
start_suffix: self.start_suffix,
value: self.value,
}
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.