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 capabilities(&self) -> TargetCapabilities;
    fn generate(
        &self,
        api: &Api,
        out_dir: &Utf8Path,
        config: &Self::Config,
    ) -> Result<()>;

    // Provided methods
    fn allows_unsupported(&self, config: &Self::Config) -> bool { ... }
    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 capabilities(&self) -> TargetCapabilities

The gated IDL features this target implements. The orchestrator refuses to run a generator against an API that uses a feature its declared capabilities do not cover — a target either generates a feature or fails loudly; it never silently omits one.

Source

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

Render the bindings under out_dir.

Provided Methods§

Source

fn allows_unsupported(&self, config: &Self::Config) -> bool

Whether the user explicitly opted in to generating this target even though the API uses features the target does not support (for example generators.wasm.allow_unsupported: true). When true the orchestrator downgrades the capability failure to a loud warning and the generator must emit an explicit unsupported surface (throwing stubs, documentation) rather than silently omitting the feature. Default: false — opting in must always be an explicit config act.

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.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§