pub struct ByteStream<B = Vec<u8>> { /* private fields */ }Expand description
A CharStream backed by raw bytes, where each byte is one symbol in
0..=255 and the stream index is the byte offset.
Generic over the backing store B: AsRef<[u8]>: use Vec<u8> for owned
bytes or &[u8] to borrow an existing buffer zero-copy. See the
module documentation for how this maps onto Rust IO primitives.
Implementations§
Source§impl ByteStream<Vec<u8>>
impl ByteStream<Vec<u8>>
Sourcepub fn from_reader(reader: impl Read) -> Result<Self>
pub fn from_reader(reader: impl Read) -> Result<Self>
Creates a byte stream by draining a std::io::Read into an owned
buffer — the bridge for files, sockets, stdin, and std::io::Cursor.
§Errors
Returns any error produced while reading reader to end.
Source§impl<B: AsRef<[u8]>> ByteStream<B>
impl<B: AsRef<[u8]>> ByteStream<B>
Sourcepub fn new(bytes: B) -> Self
pub fn new(bytes: B) -> Self
Creates a byte stream over bytes, using ANTLR’s unknown source-name
placeholder.
bytes may be an owned Vec<u8> or a borrowed &[u8] (zero-copy).
Sourcepub fn with_source_name(bytes: B, source_name: impl Into<String>) -> Self
pub fn with_source_name(bytes: B, source_name: impl Into<String>) -> Self
Creates a byte stream with an explicit source name for tokens and diagnostics.
Trait Implementations§
Source§impl<B: AsRef<[u8]>> CharStream for ByteStream<B>
impl<B: AsRef<[u8]>> CharStream for ByteStream<B>
Source§fn text(&self, interval: TextInterval) -> String
fn text(&self, interval: TextInterval) -> String
Renders the inclusive byte interval as a lowercase, separator-free hex string. See the module documentation for the rationale.
Source§fn position_summary(&self, start: usize, end: usize) -> Option<PositionSummary>
fn position_summary(&self, start: usize, end: usize) -> Option<PositionSummary>
Summarizes line/column movement over [start, end) by scanning the raw
bytes.
Without this, BaseLexer would fall back to
iterating Self::text, which is hex — so a span of N bytes would count
as 2N columns and 0x0A newline bytes would be invisible, corrupting the
line/column of split or synthesized tokens.
Source§fn symbol_at(&self, index: usize) -> Option<i32>
fn symbol_at(&self, index: usize) -> Option<i32>
fn byte_interval(&self, interval: TextInterval) -> Option<(usize, usize)>
Source§fn contiguous_ascii(&self) -> Option<&[u8]>
fn contiguous_ascii(&self) -> Option<&[u8]>
Source§fn source_text(&self) -> Option<Rc<str>>
fn source_text(&self) -> Option<Rc<str>>
fn text_source_interval( &self, _interval: TextInterval, ) -> Option<(Rc<str>, usize, usize)>
Source§impl<B: Clone> Clone for ByteStream<B>
impl<B: Clone> Clone for ByteStream<B>
Source§fn clone(&self) -> ByteStream<B>
fn clone(&self) -> ByteStream<B>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more