Expand description
Centralized naming utilities for FHIR code generation
This module provides a consistent, clean interface for converting FHIR names to valid Rust identifiers, including struct names, field names, filenames, and module names. All naming logic is centralized here to avoid duplication and ensure consistency across the codebase.
§Key Features
- Struct Naming: Converts FHIR StructureDefinition names to valid Rust struct names
- Field Naming: Converts FHIR field names to snake_case with keyword handling
- File Naming: Generates appropriate filenames for generated Rust code
- Case Conversions: Handles PascalCase, snake_case, and identifier validation
- Keyword Handling: Manages Rust keyword conflicts by appending underscores
- FHIR Conventions: Preserves FHIR naming conventions where appropriate
§Usage
use rh_codegen::naming::Naming;
use rh_codegen::fhir_types::StructureDefinition;
// Create a sample structure definition
let structure_def = StructureDefinition {
resource_type: "StructureDefinition".to_string(),
name: "Patient".to_string(),
id: "Patient".to_string(),
url: "http://hl7.org/fhir/StructureDefinition/Patient".to_string(),
version: None,
title: None,
status: "active".to_string(),
description: None,
purpose: None,
kind: "resource".to_string(),
is_abstract: false,
base_type: "DomainResource".to_string(),
base_definition: Some("http://hl7.org/fhir/StructureDefinition/DomainResource".to_string()),
differential: None,
snapshot: None,
};
// Generate struct name
let struct_name = Naming::struct_name(&structure_def);
// Convert field name
let field_name = Naming::field_name("birthDate"); // -> "birth_date"
// Generate filename
let filename = Naming::filename(&structure_def); // -> "patient.rs"
// Case conversions
let snake_case = Naming::to_snake_case("PatientName"); // -> "patient_name"
let pascal_case = Naming::to_pascal_case("patient_name"); // -> "PatientName"§Migration from Legacy Naming
This module replaces the previously scattered naming functions from:
GeneratorUtils::generate_struct_name→Naming::struct_nameGeneratorUtils::to_rust_field_name→Naming::field_nameGeneratorUtils::to_snake_case→Naming::to_snake_caseGeneratorUtils::to_filename→Naming::filenameNameGenerator::*→Naming::*FieldGenerator::to_rust_field_name→Naming::field_name
Structs§
- Naming
- Central naming utility for converting FHIR names to Rust identifiers