#[repr(C)]pub struct EncoderDesc {
pub name: &'static str,
pub write_envelope: fn(&mut dyn Write, &Machine, &Envelope<'_>) -> Result<()>,
pub write_error: fn(&mut dyn Write, &WireError) -> Result<()>,
pub can_stream: fn() -> bool,
}Expand description
An encoding as a vtable: a name plus the three operations the wire contract
needs. #[repr(C)] so codegen can reference a descriptor by address and
entry.rs can read its fields after dereferencing the pointer from the
capability table. A #[no_mangle] static of this type per encoding
(PLG_ENC_TEXT, PLG_ENC_BSON) is what codegen’s @plg_caps table points
at; encoders not listed there are unreferenced and get dead-stripped.
Fields§
§name: &'static strThe --format name this descriptor answers to (“text”, “bson”).
write_envelope: fn(&mut dyn Write, &Machine, &Envelope<'_>) -> Result<()>§write_error: fn(&mut dyn Write, &WireError) -> Result<()>§can_stream: fn() -> boolFalse ⇒ the encoding can’t coexist with streamed write/1 bytes on the
same stdout (binary formats), so the caller must run in capture mode.
Implementations§
Source§impl EncoderDesc
impl EncoderDesc
Sourcepub unsafe fn find(
caps: *const *const EncoderDesc,
len: usize,
name: &str,
) -> Option<&'static EncoderDesc>
pub unsafe fn find( caps: *const *const EncoderDesc, len: usize, name: &str, ) -> Option<&'static EncoderDesc>
Find a descriptor by name in a capability table (codegen-baked pointers
to #[no_mangle] static descriptors). Returns None when the name
isn’t advertised — entry.rs maps that to a usage error (exit 2).
§Safety
caps must point at len valid pointers to static descriptors.