pub trait Tokenize {
// Required method
fn tokenize(&self, output: &mut CellStream) -> Result<(), CellStreamError>;
// Provided method
fn to_cell_stream(&self) -> Result<CellStream, CellStreamError> { ... }
}Expand description
Converts syntax or raw tokens into structural cells.
This boundary is intentionally distinct from Lex: most macros should
preserve cell partitioning, while function-like expansion may explicitly
choose a raw TokenStream when syntax is not valid before expansion.
Implementations append to the supplied output rather than replacing its
existing cells.
§Examples
use m2_syn::{CellStream, Tokenize, lex_str};
let first = lex_str("x = 1;")?;
let second = lex_str("y = 2")?;
let mut cells = CellStream::default();
first.tokenize(&mut cells)?;
second.tokenize(&mut cells)?;
assert_eq!(cells.len(), 2);Required Methods§
Sourcefn tokenize(&self, output: &mut CellStream) -> Result<(), CellStreamError>
fn tokenize(&self, output: &mut CellStream) -> Result<(), CellStreamError>
Appends this value’s independently parseable cells to output.
§Errors
Returns CellStreamError when a raw token prefix does not end at a
complete cell boundary.
Provided Methods§
Sourcefn to_cell_stream(&self) -> Result<CellStream, CellStreamError>
fn to_cell_stream(&self) -> Result<CellStream, CellStreamError>
Tokenizes this value into a fresh cell stream.
This is the allocating convenience form of Self::tokenize.
§Errors
Returns CellStreamError when a raw token prefix does not end at a
complete cell boundary.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".