Trait rasn_compiler::prelude::Backend

source ·
pub trait Backend: Sized + Default {
    type Config: Sized + Default + Debug;

    // Required methods
    fn generate_module(
        &self,
        top_level_declarations: Vec<ToplevelDefinition>
    ) -> Result<GeneratedModule, GeneratorError>;
    fn generate(
        &self,
        tld: ToplevelDefinition
    ) -> Result<TokenStream, GeneratorError>;
    fn config(&self) -> &Self::Config;
    fn from_config(config: Self::Config) -> Self;

    // Provided method
    fn format_bindings(bindings: &str) -> Result<String, Box<dyn Error>> { ... }
}
Expand description

Implementors of the Backend trait can be used as a backend to the compiler in order to create bindings for other frameworks and languages than the default backend.

Required Associated Types§

Required Methods§

source

fn generate_module( &self, top_level_declarations: Vec<ToplevelDefinition> ) -> Result<GeneratedModule, GeneratorError>

generates bindings for an ASN.1 module

§Params
  • top_level_declarations vector of [TopLevelDeclaration]s that are defined in the ASN.1 module
source

fn generate( &self, tld: ToplevelDefinition ) -> Result<TokenStream, GeneratorError>

generates bindings for a single ASN.1 item

§Params
  • tld [TopLevelDeclaration] for which the bindings should be generated
source

fn config(&self) -> &Self::Config

Returns a reference to the backend’s config

source

fn from_config(config: Self::Config) -> Self

Creates a backend from its config

Provided Methods§

source

fn format_bindings(bindings: &str) -> Result<String, Box<dyn Error>>

Formats the bindings using the language- or framework-specific linters. For example, the Rust backend uses rustfmt for formatting bindings.

Object Safety§

This trait is not object safe.

Implementors§