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: boolEmit 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: StringTypeModeControls 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: boolWhen 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: DeriveModeControls 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
impl CodeGenConfig
Sourcepub fn with_lifetime(
self,
type_name: impl Into<String>,
lifetime: impl Into<String>,
) -> Self
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
Sourcepub fn with_x509_lifetimes(self) -> Self
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
impl CodeGenConfig
Sourcepub fn with_crate_imports() -> Self
pub fn with_crate_imports() -> Self
Create config with crate-relative imports
Sourcepub fn with_super_imports() -> Self
pub fn with_super_imports() -> Self
Create config with super-relative imports
Sourcepub fn with_custom_prefix(prefix: impl Into<String>) -> Self
pub fn with_custom_prefix(prefix: impl Into<String>) -> Self
Create config with custom module path prefix
Trait Implementations§
Source§impl Clone for CodeGenConfig
impl Clone for CodeGenConfig
Source§fn clone(&self) -> CodeGenConfig
fn clone(&self) -> CodeGenConfig
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more