Builder

Struct Builder 

Source
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

Source

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.

Source

pub fn with_config(config: DeterminismConfig) -> Self

Create builder with custom configuration

Source

pub fn with_perfect_fidelity() -> Self

Create builder with Perfect Fidelity Engine enabled

Source

pub fn with_fidelity_options(fidelity_options: FidelityOptions) -> Self

Create builder with custom fidelity options

Source

pub fn for_round_trip() -> Self

Create builder optimized for round-trip operations

Source

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 (see available_presets)
  • lock - Whether to lock the preset to prevent further modifications
§Returns
  • Ok(()) - Preset applied successfully
  • Err(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 preset
  • sony_enhanced - Sony Music enhanced features

Use available_presets to get the complete list.

Source

pub fn preset(&mut self, preset_name: &str) -> Result<&mut Self, BuildError>

Apply a preset configuration (alias for apply_preset for convenience)

Source

pub fn available_presets(&self) -> Vec<String>

Get available preset names

Source

pub fn get_preset(&self, preset_name: &str) -> Option<&PartnerPreset>

Get preset details

Source

pub fn is_preset_locked(&self) -> bool

Check if a preset is locked

Source

pub fn config(&self) -> &DeterminismConfig

Get the current configuration

Source

pub fn fidelity_options(&self) -> &FidelityOptions

Get the current fidelity options

Source

pub fn set_fidelity_options(&mut self, options: FidelityOptions) -> &mut Self

Set fidelity options

Source

pub fn enable_perfect_fidelity(&mut self) -> &mut Self

Enable Perfect Fidelity Engine with default settings

Source

pub fn disable_perfect_fidelity(&mut self) -> &mut Self

Disable Perfect Fidelity Engine

Source

pub fn with_canonicalization( &mut self, algorithm: CanonicalizationAlgorithm, ) -> &mut Self

Set canonicalization algorithm

Source

pub fn with_db_c14n(&mut self) -> &mut Self

Enable DB-C14N/1.0 canonicalization (default for DDEX)

Source

pub fn with_c14n(&mut self) -> &mut Self

Enable standard XML C14N canonicalization

Source

pub fn with_c14n11(&mut self) -> &mut Self

Enable XML C14N 1.1 canonicalization

Source

pub fn with_custom_canonicalization( &mut self, rules: CustomCanonicalizationRules, ) -> &mut Self

Set custom canonicalization rules

Source

pub fn with_verification(&mut self, config: VerificationConfig) -> &mut Self

Enable build verification

Source

pub fn with_statistics(&mut self) -> &mut Self

Enable statistics collection

Source

pub fn is_perfect_fidelity_enabled(&self) -> bool

Check if Perfect Fidelity Engine is enabled

Source

pub fn canonicalization_algorithm(&self) -> &CanonicalizationAlgorithm

Get current canonicalization algorithm

Source

pub fn with_version(&mut self, version: DdexVersion) -> &mut Self

Set target DDEX version for building

Source

pub fn target_version(&self) -> Option<DdexVersion>

Get the target DDEX version

Source

pub fn detect_version( &self, xml_content: &str, ) -> Result<DdexVersion, BuildError>

Detect version from XML content

Source

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

Source

pub fn is_version_compatible(&self, from: DdexVersion, to: DdexVersion) -> bool

Get version compatibility information

Source

pub fn supported_versions(&self) -> Vec<DdexVersion>

Get supported DDEX versions

Source

pub fn build_with_fidelity( &self, request: &BuildRequest, ) -> Result<FidelityBuildResult, BuildError>

Build DDEX XML with Perfect Fidelity Engine

Source

pub fn verify_build( &self, xml_output: &str, ) -> Result<VerificationResult, BuildError>

Verify build output meets fidelity requirements

Source

pub fn test_round_trip_fidelity( &self, original_xml: &str, ) -> Result<RoundTripResult, BuildError>

Test round-trip fidelity: XML → Parse → Build → Parse → Compare

Source

pub fn canonicalize(&self, xml_content: &str) -> Result<String, BuildError>

Canonicalize XML using the configured algorithm

Source

pub fn db_c14n_config(&self) -> DbC14NConfig

Get DB-C14N/1.0 configuration details

Trait Implementations§

Source§

impl Clone for Builder

Source§

fn clone(&self) -> Builder

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 Builder

Source§

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

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

impl Default for Builder

Source§

fn default() -> Self

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> 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> Same for T

Source§

type Output = T

Should always be Self
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.
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
Source§

impl<T> ErasedDestructor for T
where T: 'static,