pub struct Builder { /* private fields */ }
Expand description
The main DDEX Builder for creating deterministic XML output.
Builder
is the primary interface for generating DDEX-compliant XML with
guaranteed deterministic output. It supports partner presets, version conversion,
and comprehensive security features.
§Features
- Deterministic Output: Uses DB-C14N/1.0 for byte-perfect reproducibility
- Partner Presets: Pre-configured settings for major music platforms
- Version Management: Support for ERN 3.8.2, 4.2, and 4.3 with conversion
- Security: Built-in validation, rate limiting, and XXE protection
- Performance: Memory-optimized with streaming support for large files
§Usage Patterns
§Basic Usage
use ddex_builder::Builder;
let builder = Builder::new();
let available_presets = builder.available_presets();
println!("Available presets: {:?}", available_presets);
§With Partner Preset
use ddex_builder::Builder;
let mut builder = Builder::new();
builder.preset("spotify_audio_43")?;
// Builder is now configured for Spotify Audio releases (ERN 4.3)
assert!(builder.is_preset_locked() == false); // Unlocked for further customization
§Locked Preset Configuration
use ddex_builder::Builder;
let mut builder = Builder::new();
builder.apply_preset("spotify_audio_43", true)?; // Lock the preset
assert!(builder.is_preset_locked());
§Version Conversion
use ddex_builder::{Builder, DdexVersion};
use ddex_builder::versions::ConversionOptions;
let builder = Builder::new();
// Check version compatibility
let compatible = builder.is_version_compatible(
DdexVersion::Ern382,
DdexVersion::Ern43
);
if compatible {
let options = Some(ConversionOptions::default());
let result = builder.convert_version(
&xml_content,
DdexVersion::Ern382,
DdexVersion::Ern43,
options
)?;
println!("Converted XML: {}", result.converted_xml);
}
§Thread Safety
Builder
is Send + Sync
and can be safely shared between threads.
Each thread should create its own instance for best performance.
§Memory Usage
The builder uses memory-optimized data structures and streaming where possible. Typical memory usage:
- Small releases (<100KB): ~5MB
- Large releases (>1MB): ~20-50MB with streaming
Implementations§
Source§impl Builder
impl Builder
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new DDEX Builder with default configuration.
The builder is initialized with:
- Default determinism configuration for byte-perfect output
- All available partner presets loaded
- No preset locked (can be changed)
- Latest supported DDEX version as target
§Examples
use ddex_builder::Builder;
let builder = Builder::new();
assert!(!builder.is_preset_locked());
assert!(builder.available_presets().len() > 0);
§Performance
Creating a new builder is fast (~1μs) as presets are loaded from embedded configuration data.
Sourcepub fn with_config(config: DeterminismConfig) -> Self
pub fn with_config(config: DeterminismConfig) -> Self
Create builder with custom configuration
Sourcepub fn with_perfect_fidelity() -> Self
pub fn with_perfect_fidelity() -> Self
Create builder with Perfect Fidelity Engine enabled
Sourcepub fn with_fidelity_options(fidelity_options: FidelityOptions) -> Self
pub fn with_fidelity_options(fidelity_options: FidelityOptions) -> Self
Create builder with custom fidelity options
Sourcepub fn for_round_trip() -> Self
pub fn for_round_trip() -> Self
Create builder optimized for round-trip operations
Sourcepub fn apply_preset(
&mut self,
preset_name: &str,
lock: bool,
) -> Result<(), BuildError>
pub fn apply_preset( &mut self, preset_name: &str, lock: bool, ) -> Result<(), BuildError>
Applies a partner preset configuration to the builder.
Presets contain pre-configured settings optimized for specific music platforms and distribution partners. Each preset includes determinism settings, validation rules, and format preferences.
§Arguments
preset_name
- Name of the preset to apply (seeavailable_presets
)lock
- Whether to lock the preset to prevent further modifications
§Returns
Ok(())
- Preset applied successfullyErr(BuildError::InvalidFormat)
- Unknown preset name
§Examples
use ddex_builder::Builder;
let mut builder = Builder::new();
// Apply Spotify preset without locking
builder.apply_preset("spotify_audio_43", false)?;
assert!(!builder.is_preset_locked());
// Apply and lock YouTube preset
builder.apply_preset("youtube_video_43", true)?;
assert!(builder.is_preset_locked());
§Available Presets
Common presets include:
spotify_audio_43
- Spotify audio releases (ERN 4.3)youtube_video_43
- YouTube video content (ERN 4.3)apple_music_43
- Apple Music releases (ERN 4.3)universal_basic
- Universal Music basic presetsony_enhanced
- Sony Music enhanced features
Use available_presets
to get the complete list.
Sourcepub fn preset(&mut self, preset_name: &str) -> Result<&mut Self, BuildError>
pub fn preset(&mut self, preset_name: &str) -> Result<&mut Self, BuildError>
Apply a preset configuration (alias for apply_preset for convenience)
Sourcepub fn available_presets(&self) -> Vec<String>
pub fn available_presets(&self) -> Vec<String>
Get available preset names
Sourcepub fn get_preset(&self, preset_name: &str) -> Option<&PartnerPreset>
pub fn get_preset(&self, preset_name: &str) -> Option<&PartnerPreset>
Get preset details
Sourcepub fn is_preset_locked(&self) -> bool
pub fn is_preset_locked(&self) -> bool
Check if a preset is locked
Sourcepub fn config(&self) -> &DeterminismConfig
pub fn config(&self) -> &DeterminismConfig
Get the current configuration
Sourcepub fn fidelity_options(&self) -> &FidelityOptions
pub fn fidelity_options(&self) -> &FidelityOptions
Get the current fidelity options
Sourcepub fn set_fidelity_options(&mut self, options: FidelityOptions) -> &mut Self
pub fn set_fidelity_options(&mut self, options: FidelityOptions) -> &mut Self
Set fidelity options
Sourcepub fn enable_perfect_fidelity(&mut self) -> &mut Self
pub fn enable_perfect_fidelity(&mut self) -> &mut Self
Enable Perfect Fidelity Engine with default settings
Sourcepub fn disable_perfect_fidelity(&mut self) -> &mut Self
pub fn disable_perfect_fidelity(&mut self) -> &mut Self
Disable Perfect Fidelity Engine
Sourcepub fn with_canonicalization(
&mut self,
algorithm: CanonicalizationAlgorithm,
) -> &mut Self
pub fn with_canonicalization( &mut self, algorithm: CanonicalizationAlgorithm, ) -> &mut Self
Set canonicalization algorithm
Sourcepub fn with_db_c14n(&mut self) -> &mut Self
pub fn with_db_c14n(&mut self) -> &mut Self
Enable DB-C14N/1.0 canonicalization (default for DDEX)
Sourcepub fn with_c14n11(&mut self) -> &mut Self
pub fn with_c14n11(&mut self) -> &mut Self
Enable XML C14N 1.1 canonicalization
Sourcepub fn with_custom_canonicalization(
&mut self,
rules: CustomCanonicalizationRules,
) -> &mut Self
pub fn with_custom_canonicalization( &mut self, rules: CustomCanonicalizationRules, ) -> &mut Self
Set custom canonicalization rules
Sourcepub fn with_verification(&mut self, config: VerificationConfig) -> &mut Self
pub fn with_verification(&mut self, config: VerificationConfig) -> &mut Self
Enable build verification
Sourcepub fn with_statistics(&mut self) -> &mut Self
pub fn with_statistics(&mut self) -> &mut Self
Enable statistics collection
Sourcepub fn is_perfect_fidelity_enabled(&self) -> bool
pub fn is_perfect_fidelity_enabled(&self) -> bool
Check if Perfect Fidelity Engine is enabled
Sourcepub fn canonicalization_algorithm(&self) -> &CanonicalizationAlgorithm
pub fn canonicalization_algorithm(&self) -> &CanonicalizationAlgorithm
Get current canonicalization algorithm
Sourcepub fn with_version(&mut self, version: DdexVersion) -> &mut Self
pub fn with_version(&mut self, version: DdexVersion) -> &mut Self
Set target DDEX version for building
Sourcepub fn target_version(&self) -> Option<DdexVersion>
pub fn target_version(&self) -> Option<DdexVersion>
Get the target DDEX version
Sourcepub fn detect_version(
&self,
xml_content: &str,
) -> Result<DdexVersion, BuildError>
pub fn detect_version( &self, xml_content: &str, ) -> Result<DdexVersion, BuildError>
Detect version from XML content
Sourcepub fn convert_version(
&self,
xml_content: &str,
from_version: DdexVersion,
to_version: DdexVersion,
options: Option<ConversionOptions>,
) -> Result<ConverterResult, BuildError>
pub fn convert_version( &self, xml_content: &str, from_version: DdexVersion, to_version: DdexVersion, options: Option<ConversionOptions>, ) -> Result<ConverterResult, BuildError>
Convert XML between DDEX versions
Sourcepub fn is_version_compatible(&self, from: DdexVersion, to: DdexVersion) -> bool
pub fn is_version_compatible(&self, from: DdexVersion, to: DdexVersion) -> bool
Get version compatibility information
Sourcepub fn supported_versions(&self) -> Vec<DdexVersion>
pub fn supported_versions(&self) -> Vec<DdexVersion>
Get supported DDEX versions
Sourcepub fn build_with_fidelity(
&self,
request: &BuildRequest,
) -> Result<FidelityBuildResult, BuildError>
pub fn build_with_fidelity( &self, request: &BuildRequest, ) -> Result<FidelityBuildResult, BuildError>
Build DDEX XML with Perfect Fidelity Engine
Sourcepub fn verify_build(
&self,
xml_output: &str,
) -> Result<VerificationResult, BuildError>
pub fn verify_build( &self, xml_output: &str, ) -> Result<VerificationResult, BuildError>
Verify build output meets fidelity requirements
Sourcepub fn test_round_trip_fidelity(
&self,
original_xml: &str,
) -> Result<RoundTripResult, BuildError>
pub fn test_round_trip_fidelity( &self, original_xml: &str, ) -> Result<RoundTripResult, BuildError>
Test round-trip fidelity: XML → Parse → Build → Parse → Compare
Sourcepub fn canonicalize(&self, xml_content: &str) -> Result<String, BuildError>
pub fn canonicalize(&self, xml_content: &str) -> Result<String, BuildError>
Canonicalize XML using the configured algorithm
Sourcepub fn db_c14n_config(&self) -> DbC14NConfig
pub fn db_c14n_config(&self) -> DbC14NConfig
Get DB-C14N/1.0 configuration details
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Builder
impl RefUnwindSafe for Builder
impl Send for Builder
impl Sync for Builder
impl Unpin for Builder
impl UnwindSafe for Builder
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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