pub fn emit_section<E, O>(
    section: ModuleSection,
    output: &mut O,
    emit: E,
) -> Result<usize, EmitError>
where
    O: Write,
    E: Fn(&mut dyn Write) -> Result<usize, EmitError>,
{
    let mut bytes = 0;
    let mut counter = CountingWrite::new();

    emit(&mut counter)?;

    bytes += emit_byte(section as u8, output)?;
    bytes += emit_usize(counter.bytes(), output)?;
    bytes += emit(output)?;

    Ok(bytes)
}
/// Emits a module section to the given output.
/// Sections need to be prefixed by their length.
/// Since we do not know the length of the emitted contents ahead of time,
/// a buffer is used to hold the emitted values and copy the buffer contents to the output.
/// The buffer is reset before emitting content and after it is copied.
Emits a module section to the given output.
Sections need to be prefixed by their length.
Since we do not know the length of the emitted contents ahead of time,
a buffer is used to hold the emitted values and copy the buffer contents to the output.
The buffer is reset before emitting content and after it is copied.
Emits a module section to the given output . Sections need to be prefixed by their length . Since we do not know the length of the emitted contents ahead of time a buffer is used to hold the emitted values and copy the buffer contents to the output . The buffer is reset before emitting content and after it is copied .
pub fn emit_section<E, O>(
    section: ModuleSection,
    output: &mut O,
    emit: E,
) -> Result<usize, EmitError>
where
    O: Write,
    E: Fn(&mut dyn Write) -> Result<usize, EmitError>,
{
    let mut bytes = 0;
    let mut counter = CountingWrite::new();
    emit(&mut counter)?;
    bytes += emit_byte(section as u8, output)?;
    bytes += emit_usize(counter.bytes(), output)?;
    bytes += emit(output)?;
    Ok(bytes)
}
pub fn emit_section < E , O > ( section : ModuleSection , output : & mut O , emit : E , ) -> Result < usize , EmitError > where O : Write , E : Fn ( & mut dyn Write ) -> Result < usize , EmitError > , { let mut bytes = 0 ; let mut counter = CountingWrite :: new ( ) ; emit ( & mut counter ) ? ; bytes += emit_byte ( section as u8 , output ) ? ; bytes += emit_usize ( counter . bytes ( ) , output ) ? ; bytes += emit ( output ) ? ; Ok ( bytes ) }
Emits a module section to the given output.
Emits a module section to the given output .
section
ModuleSection
output
&mut O
emit
E
section
ModuleSection
output
&mut O
emit
E