Generates Rust that decodes Kiwi data for a schema inside a Rustler NIF.
source/2 returns a complete Rust source file: decoders for the schema's
definitions, the helpers they share, and NIF entrypoints. Call it from
rustq.exs, where mix rustq.gen writes the file and mix rustq.gen --check
keeps it fresh. The crate provides the Decoder<'a> the generated code reads
with; KiwiCodec.RustlerGenerator.Decoder describes it and ships a complete
one.
The generator needs RustQ, an optional dependency, and exists only where RustQ is available. Native decoders covers each feature.
Summary
Functions
Returns a complete Rust source file for generated Rustler decoders.
Types
Functions
@spec source( KiwiCodec.Schema.t(), keyword() ) :: String.t()
Returns a complete Rust source file for generated Rustler decoders.
generate :native_decoders, "native/my_nif/src/generated.rs" do
schema = KiwiCodec.parse_schema!(File.read!("priv/schema.kiwi"))
content KiwiCodec.RustlerGenerator.source(schema,
entrypoints: ["Node"],
module_prefix: "Example.Schema"
)
endOptions:
:definitions- schema definition names to generate, including their dependencies. Defaults to the requested entrypoint definitions, or all definitions when no entrypoints are requested.:entrypoints-:all,{:nif_stubs, module}, a NIF stub module, definition names, or{nif_name, definition_name}entries for generated NIFs. Definition names inferdecode_<definition_name>NIFs.:allgenerates one inferred NIF for every schema definition. A NIF stub module infers entries from one-aritydecode_*stubs whose suffix matches a schema definition. For{:nif_stubs, module}, the module must exposestubs/0.:module_prefix- Elixir module prefix for decoded structs.:decoder- Rust path imported asDecoder. Defaults to"crate::runtime::Decoder". Its methods have the signaturesKiwiCodec.RustlerGenerator.Decoderlists.:features- decoder families to generate. Defaults to[:full]. Use:sparseand:skipfor generic sparse map decoders and skip helpers used by projection-oriented native backends, and:recordsfor native records Rust code can work with before encoding them; seeKiwiCodec.RustlerGenerator.Records.:unknown_fields- how message decoders handle fields the schema does not define::error(default) rejects the data;:runtime_schemaskips them using a schema read with the data. SeeKiwiCodec.RustlerGenerator.UnknownFieldsfor theDecodercontract.