Skip to main content

CodeGenConfig

Struct CodeGenConfig 

Source
pub struct CodeGenConfig {
    pub module_path_prefix: Option<String>,
    pub use_core: bool,
    pub skip_imported_types: HashSet<String>,
    pub imported_type_lifetimes: HashMap<String, String>,
    pub string_type_mode: StringTypeMode,
    pub any_as_raw_der: bool,
    pub derive_mode: DeriveMode,
    pub raw_der_fields: HashSet<String>,
}
Expand description

Configuration options for code generation

Fields§

§module_path_prefix: Option<String>

Module path prefix for imports (e.g., “crate”, “super”, or custom path) If None, imports are only documented in comments

§use_core: bool

Emit core::convert::TryFrom instead of std::convert::TryFrom. Use this when generating code for #![no_std] environments.

§skip_imported_types: HashSet<String>

Set of imported type names that should be skipped during code generation Types in this set are assumed to come from external modules

§imported_type_lifetimes: HashMap<String, String>

Map of imported type names to their lifetime requirements Key: type name, Value: lifetime parameter (e.g., “’a”) If a type is not in this map, it’s assumed to not require a lifetime

§string_type_mode: StringTypeMode

Controls whether string/binary ASN.1 types (OCTET STRING, BIT STRING, UTF8String, PrintableString, IA5String) are generated as owned heap-allocating types or as zero-copy borrowed Ref variants. Defaults to StringTypeMode::Owned.

§any_as_raw_der: bool

When true, ANY and ANY DEFINED BY fields are generated as RawDer<'a> (zero-copy raw TLV capture) instead of Element<'a>.

Use this for schemas where every open-typed field should be stored as raw bytes for lazy decoding rather than eagerly parsed into an Element tree. The generated type aliases and struct fields are then RawDer<'a>, which implements both Decode<'a> (reads any TLV) and DecodeImplicit<'a> (captures the value bytes of an IMPLICIT-tagged field).

Defaults to false.

§derive_mode: DeriveMode

Controls how derive macros (Asn1Sequence, Asn1Choice, Asn1Set) and their helper attributes are emitted.

Defaults to DeriveMode::FeatureGated, which wraps every derive annotation in #[cfg_attr(feature = "derive", …)]. Set to DeriveMode::Always to emit them unconditionally, which removes the need for the consuming crate to declare a derive Cargo feature.

§raw_der_fields: HashSet<String>

Set of field names (after to_snake_case conversion) that should be emitted as RawDer<'a> regardless of their ASN.1 type.

Use this to defer decoding of expensive fields — such as issuer, subject, and extensions in an X.509 TBSCertificate — until the caller explicitly requests them. The field is stored as a zero-copy TLV capture that can be decoded lazily.

Fields listed here are always emitted with the 'a lifetime, which is propagated to the enclosing struct declaration automatically.

Defaults to an empty set (no override).

Implementations§

Source§

impl CodeGenConfig

Source

pub fn with_lifetime( self, type_name: impl Into<String>, lifetime: impl Into<String>, ) -> Self

Add a type that requires a lifetime parameter when imported

Source

pub fn with_x509_lifetimes(self) -> Self

Configure common X.509 types that require lifetimes This also marks which types should be skipped (imported from external crates) vs which types should be generated locally

Source§

impl CodeGenConfig

Source

pub fn with_crate_imports() -> Self

Create config with crate-relative imports

Source

pub fn with_super_imports() -> Self

Create config with super-relative imports

Source

pub fn with_custom_prefix(prefix: impl Into<String>) -> Self

Create config with custom module path prefix

Trait Implementations§

Source§

impl Clone for CodeGenConfig

Source§

fn clone(&self) -> CodeGenConfig

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for CodeGenConfig

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for CodeGenConfig

Source§

fn default() -> CodeGenConfig

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.