Skip to main content

ExtensionHandler

Trait ExtensionHandler 

Source
pub trait ExtensionHandler: Send + Sync {
    // Required methods
    fn extension_type(&self) -> Extension;
    fn validate(&self, model: &Model) -> Result<()>;

    // Provided methods
    fn namespace(&self) -> &'static str { ... }
    fn name(&self) -> &'static str { ... }
    fn is_used_in_model(&self, _model: &Model) -> bool { ... }
    fn pre_write(&self, _model: &mut Model) -> Result<()> { ... }
    fn post_parse(&self, _model: &mut Model) -> Result<()> { ... }
}
Expand description

Handler trait for 3MF extensions

This trait defines the interface that all extension handlers must implement. It provides hooks for parsing, validation, and writing extension-specific data.

§Example

struct MyExtensionHandler;

impl ExtensionHandler for MyExtensionHandler {
    fn extension_type(&self) -> Extension {
        Extension::Material
    }

    fn validate(&self, model: &Model) -> Result<()> {
        // Perform extension-specific validation
        Ok(())
    }
}

Required Methods§

Source

fn extension_type(&self) -> Extension

Returns the extension type this handler supports

Source

fn validate(&self, model: &Model) -> Result<()>

Validate extension-specific data in the model

This method is called during model validation to check extension-specific constraints and requirements.

§Arguments
  • model - The 3MF model to validate
§Returns
  • Ok(()) if validation passes
  • Err(...) if validation fails with a specific error

Provided Methods§

Source

fn namespace(&self) -> &'static str

Returns the namespace URI for this extension

Source

fn name(&self) -> &'static str

Returns a human-readable name for this extension

Source

fn is_used_in_model(&self, _model: &Model) -> bool

Check if the extension is present in the model

This method can be used to determine if the model actually uses this extension. The default implementation always returns true, but extensions can override this to provide more specific detection.

§Arguments
  • model - The 3MF model to check
§Returns
  • true if the extension is used in the model
  • false otherwise
Source

fn pre_write(&self, _model: &mut Model) -> Result<()>

Called before writing extension-specific data

This hook allows extensions to prepare or transform data before serialization. The default implementation does nothing.

§Arguments
  • model - Mutable reference to the model being written
Source

fn post_parse(&self, _model: &mut Model) -> Result<()>

Called after parsing extension-specific data

This hook allows extensions to post-process or validate data after parsing. The default implementation does nothing.

§Arguments
  • model - Mutable reference to the parsed model

Implementors§