Skip to main content

CodeGenerator

Struct CodeGenerator 

Source
pub struct CodeGenerator { /* private fields */ }
Expand description

Main code generator struct that orchestrates specialized generators

Uses Arc<Mutex<>> for shared mutable state to enable parallel generation of independent StructureDefinitions via rayon.

Implementations§

Source§

impl CodeGenerator

Source

pub fn new(config: CodegenConfig) -> Self

Create a new code generator with the given configuration

Source

pub fn new_with_value_set_directory<P: AsRef<Path>>( config: CodegenConfig, value_set_dir: P, ) -> Self

Create a new code generator with a ValueSet directory

Source

pub fn load_structure_definition<P: AsRef<Path>>( &self, path: P, ) -> CodegenResult<StructureDefinition>

Load and parse a FHIR StructureDefinition from a JSON file

Source

pub fn generate_struct( &mut self, structure_def: &StructureDefinition, ) -> CodegenResult<RustStruct>

Generate a Rust struct from a FHIR StructureDefinition

Source

pub fn generate_trait( &mut self, structure_def: &StructureDefinition, ) -> CodegenResult<Vec<RustTrait>>

Generate traits for a structure definition

Source

pub fn generate_to_organized_directories<P: AsRef<Path>>( &mut self, structure_def: &StructureDefinition, base_output_dir: P, ) -> CodegenResult<()>

Generate a Rust struct and write it to the appropriate directory based on FHIR type classification

Source

pub fn generate_trait_to_organized_directory<P: AsRef<Path>>( &mut self, structure_def: &StructureDefinition, base_output_dir: P, ) -> CodegenResult<()>

Generate traits and write them to the traits directory

Source

pub fn classify_fhir_structure_def( &self, structure_def: &StructureDefinition, ) -> FhirTypeCategory

Classify a FHIR StructureDefinition into the appropriate category

Source

pub fn generate_to_file<P: AsRef<Path>>( &mut self, structure_def: &StructureDefinition, output_path: P, ) -> CodegenResult<()>

Generate a Rust struct and write it to a file

Source

pub fn generate_trait_to_file<P: AsRef<Path>>( &mut self, structure_def: &StructureDefinition, output_path: P, ) -> CodegenResult<()>

Generate a Rust trait and write it to a file

Source

pub fn pre_register_value_set_enums<P: AsRef<Path>>( &mut self, package_dir: P, ) -> CodegenResult<()>

Pre-scan and register all ValueSet enums in the TypeRegistry This should be called before processing resources to ensure correct import paths

Source

pub fn generate_enum_files<P: AsRef<Path>>( &mut self, enums_dir: P, ) -> CodegenResult<()>

Generate all ValueSet enums to separate files in the specified directory

Source

pub fn generate_enums_mod_file<P: AsRef<Path>>( &mut self, enums_dir: P, ) -> CodegenResult<()>

Generate a mod.rs file that re-exports all the enum modules

Source

pub fn generate_enum_for_value_set( &mut self, value_set_url: &str, ) -> CodegenResult<Option<RustEnum>>

Generate an enum for a value set binding

Source

pub fn has_cached_enums(&self) -> bool

Check if any ValueSet enums have been generated

Source

pub fn to_filename(&self, structure_def: &StructureDefinition) -> String

Convert a FHIR resource type name to filename using snake_case

Source

pub fn pre_generate_base_definitions( &mut self, structure_defs: &[StructureDefinition], )

Pre-generate base definitions (Element, BackboneElement, DomainResource, Resource) to ensure they’re in the type_cache before parallel generation begins.

These core FHIR types are referenced by virtually every other type, so generating them first eliminates lock contention during the parallel phase and avoids redundant re-generation attempts.

Source

pub fn generate_trait_file_from_trait<P: AsRef<Path>>( &self, rust_trait: &RustTrait, output_path: P, ) -> CodegenResult<()>

Generate a trait file directly from a RustTrait object

Source

pub fn type_cache_snapshot(&self) -> HashMap<String, RustStruct>

Get a clone of the shared type cache (for reading generated structs)

Source

pub fn generate_structs_parallel( &self, structure_defs: &[StructureDefinition], ) -> Vec<(String, CodegenResult<RustStruct>)>

Generate Rust structs for multiple StructureDefinitions in parallel using rayon.

This processes the CPU-intensive struct generation phase in parallel while maintaining thread-safe access to shared state via Arc<Mutex<>>. Returns a vector of (StructureDefinition, Result) pairs.

§Performance

On a machine with N cores, this typically achieves ~N× speedup for the struct generation phase compared to sequential processing, as each StructureDefinition’s struct generation is largely independent.

The TypeRegistry must be fully populated (Phase 1 complete) before calling this.

Source

pub fn write_all_generated_files<P: AsRef<Path>>( &self, structure_defs: &[StructureDefinition], base_output_dir: P, ) -> Vec<CodegenResult<()>>

Generate files for all generated structs in the type cache.

This is the I/O phase that writes generated Rust code to disk. It should be called after generate_structs_parallel (or sequential generation) has populated the type cache.

Source

pub fn write_all_trait_files<P: AsRef<Path>>( &self, structure_defs: &[StructureDefinition], base_output_dir: P, ) -> Vec<CodegenResult<()>>

Generate trait files for all resources and profiles in parallel.

This writes trait files for resources/profiles that have been generated.

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> ErasedDestructor for T
where T: 'static,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

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

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. 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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more