pub trait SyntaxWrite {
type Error: Error;
Show 27 methods
// Required methods
fn begin_element(
&mut self,
name: &str,
params: Option<&str>,
) -> Result<(), Self::Error>;
fn end_element(&mut self) -> Result<(), Self::Error>;
fn fixed_width_field(
&mut self,
field: &FixedWidthField<'_>,
) -> Result<(), Self::Error>;
fn variable_length_field(
&mut self,
field: &VariableLengthField<'_>,
) -> Result<(), Self::Error>;
fn bit_pattern(
&mut self,
field: &BitPatternField<'_>,
) -> Result<(), Self::Error>;
fn raw_bytes(&mut self, data: &[u8]) -> Result<(), Self::Error>;
fn begin_if(
&mut self,
condition: &str,
terms: &[TermAnnotation<'_>],
taken: bool,
) -> Result<(), Self::Error>;
fn begin_else_if(
&mut self,
condition: &str,
terms: &[TermAnnotation<'_>],
taken: bool,
) -> Result<(), Self::Error>;
fn begin_else(&mut self, taken: bool) -> Result<(), Self::Error>;
fn end_if(&mut self) -> Result<(), Self::Error>;
fn begin_for(
&mut self,
header: &str,
terms: &[TermAnnotation<'_>],
) -> Result<(), Self::Error>;
fn for_iteration(
&mut self,
variable: &str,
index: u64,
) -> Result<(), Self::Error>;
fn end_for(&mut self) -> Result<(), Self::Error>;
fn begin_while(&mut self, condition: &str) -> Result<(), Self::Error>;
fn while_iteration(&mut self, index: u64) -> Result<(), Self::Error>;
fn end_while(&mut self) -> Result<(), Self::Error>;
fn begin_do_while(&mut self) -> Result<(), Self::Error>;
fn do_while_iteration(&mut self, index: u64) -> Result<(), Self::Error>;
fn end_do_while(&mut self, condition: &str) -> Result<(), Self::Error>;
fn begin_switch(
&mut self,
expression: &str,
terms: &[TermAnnotation<'_>],
) -> Result<(), Self::Error>;
fn begin_case(
&mut self,
label: &str,
taken: bool,
) -> Result<(), Self::Error>;
fn end_case(&mut self) -> Result<(), Self::Error>;
fn end_switch(&mut self) -> Result<(), Self::Error>;
fn assignment(
&mut self,
expression: &str,
computed_value: Option<&Value>,
) -> Result<(), Self::Error>;
fn comment(&mut self, text: &str) -> Result<(), Self::Error>;
fn ellipsis(&mut self) -> Result<(), Self::Error>;
// Provided method
fn field_table(&mut self, table: &FieldTable<'_>) -> Result<(), Self::Error> { ... }
}Expand description
Trait for rendering MPEG specification syntax structures.
Renderers implement this trait to produce output in a specific format (plain text, ANSI-colored text, HTML, etc.). Producers call these methods to describe the syntax structure and field values.
Methods use begin_/end_ pairs rather than closures to avoid
borrow-checker issues when the producer needs &mut W inside a
closure while also borrowing &self for data access.
Required Associated Types§
Required Methods§
Sourcefn begin_element(
&mut self,
name: &str,
params: Option<&str>,
) -> Result<(), Self::Error>
fn begin_element( &mut self, name: &str, params: Option<&str>, ) -> Result<(), Self::Error>
Begin a named syntax element (a “syntax table” in MPEG specs).
params is None for unparameterized elements like transport_packet(),
or Some("payloadType, payloadSize") for parameterized ones like
sei_payload(payloadType, payloadSize).
Sourcefn end_element(&mut self) -> Result<(), Self::Error>
fn end_element(&mut self) -> Result<(), Self::Error>
End the current syntax element.
Sourcefn fixed_width_field(
&mut self,
field: &FixedWidthField<'_>,
) -> Result<(), Self::Error>
fn fixed_width_field( &mut self, field: &FixedWidthField<'_>, ) -> Result<(), Self::Error>
Render a fixed-width field.
Sourcefn variable_length_field(
&mut self,
field: &VariableLengthField<'_>,
) -> Result<(), Self::Error>
fn variable_length_field( &mut self, field: &VariableLengthField<'_>, ) -> Result<(), Self::Error>
Render a variable-length coded field.
Sourcefn bit_pattern(
&mut self,
field: &BitPatternField<'_>,
) -> Result<(), Self::Error>
fn bit_pattern( &mut self, field: &BitPatternField<'_>, ) -> Result<(), Self::Error>
Render a fixed bit pattern or marker bit.
Sourcefn raw_bytes(&mut self, data: &[u8]) -> Result<(), Self::Error>
fn raw_bytes(&mut self, data: &[u8]) -> Result<(), Self::Error>
Render raw bytes as a hex dump. Called after a field template line; the renderer formats as hex lines (16 bytes per line).
Sourcefn begin_if(
&mut self,
condition: &str,
terms: &[TermAnnotation<'_>],
taken: bool,
) -> Result<(), Self::Error>
fn begin_if( &mut self, condition: &str, terms: &[TermAnnotation<'_>], taken: bool, ) -> Result<(), Self::Error>
Begin an if block. The renderer adds if (condition) { and any
term annotations. taken is a hint for dimming not-taken branches.
Sourcefn begin_else_if(
&mut self,
condition: &str,
terms: &[TermAnnotation<'_>],
taken: bool,
) -> Result<(), Self::Error>
fn begin_else_if( &mut self, condition: &str, terms: &[TermAnnotation<'_>], taken: bool, ) -> Result<(), Self::Error>
Close the previous branch and open an else if branch.
Sourcefn begin_else(&mut self, taken: bool) -> Result<(), Self::Error>
fn begin_else(&mut self, taken: bool) -> Result<(), Self::Error>
Close the previous branch and open an else branch.
Sourcefn end_if(&mut self) -> Result<(), Self::Error>
fn end_if(&mut self) -> Result<(), Self::Error>
Close the final branch of an if/else-if/else chain.
Sourcefn begin_for(
&mut self,
header: &str,
terms: &[TermAnnotation<'_>],
) -> Result<(), Self::Error>
fn begin_for( &mut self, header: &str, terms: &[TermAnnotation<'_>], ) -> Result<(), Self::Error>
Begin a for loop. header is the loop clause, e.g.
"i = 0; i < N; i++". The renderer adds for (header) {.
Sourcefn for_iteration(
&mut self,
variable: &str,
index: u64,
) -> Result<(), Self::Error>
fn for_iteration( &mut self, variable: &str, index: u64, ) -> Result<(), Self::Error>
Mark a for-loop iteration with the variable name and index.
Sourcefn while_iteration(&mut self, index: u64) -> Result<(), Self::Error>
fn while_iteration(&mut self, index: u64) -> Result<(), Self::Error>
Mark a while-loop iteration.
Sourcefn begin_do_while(&mut self) -> Result<(), Self::Error>
fn begin_do_while(&mut self) -> Result<(), Self::Error>
Begin a do-while loop.
Sourcefn do_while_iteration(&mut self, index: u64) -> Result<(), Self::Error>
fn do_while_iteration(&mut self, index: u64) -> Result<(), Self::Error>
Mark a do-while iteration.
Sourcefn end_do_while(&mut self, condition: &str) -> Result<(), Self::Error>
fn end_do_while(&mut self, condition: &str) -> Result<(), Self::Error>
End a do-while loop with the given condition.
Sourcefn begin_switch(
&mut self,
expression: &str,
terms: &[TermAnnotation<'_>],
) -> Result<(), Self::Error>
fn begin_switch( &mut self, expression: &str, terms: &[TermAnnotation<'_>], ) -> Result<(), Self::Error>
Begin a switch statement. expression is the switch discriminator,
e.g. "id". terms provides term annotations for the discriminator.
Sourcefn begin_case(&mut self, label: &str, taken: bool) -> Result<(), Self::Error>
fn begin_case(&mut self, label: &str, taken: bool) -> Result<(), Self::Error>
Begin a case within a switch. label is the case label,
e.g. "ID_CPE". taken indicates whether this is the active case.
Sourcefn end_switch(&mut self) -> Result<(), Self::Error>
fn end_switch(&mut self) -> Result<(), Self::Error>
End the switch statement.
Provided Methods§
Sourcefn field_table(&mut self, table: &FieldTable<'_>) -> Result<(), Self::Error>
fn field_table(&mut self, table: &FieldTable<'_>) -> Result<(), Self::Error>
Render a table of homogeneous field values from a loop.
The default implementation expands the table into a for loop with
one iteration per row. Compact renderers override this to produce
inline lists or aligned tables.