Skip to main content

Generator

Trait Generator 

Source
pub trait Generator: Send + Sync {
    type Config: Serialize + Default + Clone + Send + Sync;

    // Required methods
    fn name(&self) -> &'static str;
    fn generate(
        &self,
        api: &Api,
        out_dir: &Utf8Path,
        config: &Self::Config,
    ) -> Result<()>;

    // Provided method
    fn output_files(
        &self,
        _api: &Api,
        _out_dir: &Utf8Path,
        _config: &Self::Config,
    ) -> Vec<String> { ... }
}
Expand description

A language code generator.

Generators are dispatched in parallel, so every implementation must be safe to share across threads. The associated Config type is owned by the generator crate so weaveffi-core does not have to know about target-specific options like swift_module_name or cpp_namespace.

Required Associated Types§

Source

type Config: Serialize + Default + Clone + Send + Sync

Per-target, fully-typed configuration consumed by generate and output_files. Must round-trip through serde_json so the orchestrator can hash it as part of the cache key.

Required Methods§

Source

fn name(&self) -> &'static str

Stable short name for the target ("swift", "c", "node", …). Used as the cache file basename and the --target filter token.

Source

fn generate( &self, api: &Api, out_dir: &Utf8Path, config: &Self::Config, ) -> Result<()>

Render the bindings under out_dir.

Provided Methods§

Source

fn output_files( &self, _api: &Api, _out_dir: &Utf8Path, _config: &Self::Config, ) -> Vec<String>

Files that generate would write, relative to (or anchored under) out_dir. Used by --dry-run and diff. Default implementation returns the empty list; generators override to surface the list without doing any I/O.

Implementors§