1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
//! The `generator` module is responsible for generating rust code that handles
//! decoding and encoding of the parsed and validated ASN1 data elements.
//! The `generator` uses string templates for generating rust code.
use std::error::Error;
use crate::intermediate::ToplevelDefinition;
use self::error::GeneratorError;
pub mod error;
pub mod rasn;
/// 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.
pub trait Backend: Sized {
/// generates bindings for an ASN.1 module
/// ### Params
/// - `top_level_declarations` vector of [TopLevelDeclaration]s that are defined in the ASN.1 module
fn generate_module(
&self,
top_level_declarations: Vec<ToplevelDefinition>,
) -> Result<GeneratedModule, GeneratorError>;
}
pub struct GeneratedModule {
pub generated: Option<String>,
pub warnings: Vec<Box<dyn Error>>,
}
impl GeneratedModule {
pub fn empty() -> Self {
Self {
generated: None,
warnings: vec![],
}
}
}