Skip to main content

Model

Struct Model 

Source
pub struct Model {
    pub unit: String,
    pub xmlns: String,
    pub required_extensions: Vec<Extension>,
    pub required_custom_extensions: Vec<String>,
    pub metadata: Vec<MetadataEntry>,
    pub thumbnail: Option<Thumbnail>,
    pub resources: Resources,
    pub build: Build,
    pub secure_content: Option<SecureContentInfo>,
}
Expand description

Complete 3MF model

Fields§

§unit: String

Unit of measurement (e.g., “millimeter”, “inch”)

§xmlns: String

XML namespace

§required_extensions: Vec<Extension>

Required extensions for this model Extensions that the consumer must support to properly process this file

§required_custom_extensions: Vec<String>

Required custom extension namespaces (not part of standard 3MF)

§metadata: Vec<MetadataEntry>

Metadata entries with name, value, and optional preservation flag

§thumbnail: Option<Thumbnail>

Thumbnail metadata (if present in the package)

§resources: Resources

Resources (objects, materials)

§build: Build

Build specification

§secure_content: Option<SecureContentInfo>

Secure content information (if secure content extension is used)

Implementations§

Source§

impl Model

Source

pub fn new() -> Self

Create a new empty model

Source

pub fn get_metadata(&self, name: &str) -> Option<&str>

Get metadata value by name (helper for backward compatibility)

Source

pub fn has_metadata(&self, name: &str) -> bool

Check if metadata entry exists with the given name

Source§

impl Model

Source

pub fn from_reader<R: Read + Seek>(reader: R) -> Result<Self>

Parse a 3MF file from a reader

This method uses the default parser configuration which supports all known extensions. For backward compatibility, this will accept files with any required extensions.

§Arguments
  • reader - A reader containing the 3MF file data
§Example
use lib3mf::Model;
use std::fs::File;

let file = File::open("model.3mf")?;
let model = Model::from_reader(file)?;
Source

pub fn from_reader_with_config<R: Read + Seek>( reader: R, config: ParserConfig, ) -> Result<Self>

Parse a 3MF file from a reader with custom configuration

This method allows you to specify which extensions you support. If the file requires an extension you don’t support, an error will be returned.

§Arguments
  • reader - A reader containing the 3MF file data
  • config - Parser configuration specifying supported extensions
§Example
use lib3mf::{Model, ParserConfig, Extension};
use std::fs::File;

let file = File::open("model.3mf")?;

// Only support core and material extensions
let config = ParserConfig::new()
    .with_extension(Extension::Material);

let model = Model::from_reader_with_config(file, config)?;
Source

pub fn read_thumbnail<R: Read + Seek>(reader: R) -> Result<Option<Vec<u8>>>

Read thumbnail binary data from a 3MF file

Returns the thumbnail image data as a byte vector if a thumbnail is present. Returns None if no thumbnail is found.

This is a convenience method that reads the thumbnail from a separate reader. The model metadata must have already been parsed to know if a thumbnail exists.

§Arguments
  • reader - A reader containing the 3MF file data
§Example
use lib3mf::Model;
use std::fs::File;

let file = File::open("model.3mf")?;
if let Some(thumbnail_data) = Model::read_thumbnail(file)? {
    println!("Thumbnail size: {} bytes", thumbnail_data.len());
    std::fs::write("thumbnail.png", thumbnail_data)?;
}
Source

pub fn to_writer<W: Write + Seek>(self, writer: W) -> Result<W>

Write a 3MF file to a writer

This method serializes the Model to a complete 3MF file (ZIP archive) and writes it to the provided writer.

§Arguments
  • writer - A writer to write the 3MF file data to
§Example
use lib3mf::Model;
use std::fs::File;

let mut model = Model::new();
// ... populate model with data ...

let file = File::create("output.3mf")?;
model.to_writer(file)?;
Source

pub fn to_writer_with_registry<W: Write + Seek>( self, writer: W, registry: &ExtensionRegistry, ) -> Result<W>

Write a 3MF file to a writer with extension registry

This method serializes the Model to a complete 3MF file (ZIP archive) and writes it to the provided writer. Before serialization, it calls pre_write() on all registered extension handlers, allowing extensions to prepare or transform data before writing.

§Arguments
  • writer - A writer to write the 3MF file data to
  • registry - Extension registry containing handlers that will be called before writing
§Example
use lib3mf::{Model, create_default_registry};
use std::fs::File;

let mut model = Model::new();
// ... populate model with data ...

// Create registry with all standard extension handlers
let registry = create_default_registry();

let file = File::create("output.3mf")?;
model.to_writer_with_registry(file, &registry)?;
Source

pub fn write_to_file<P: AsRef<Path>>(self, path: P) -> Result<()>

Write a 3MF file to a file path

This is a convenience method that creates a file and writes the 3MF data to it. The file is automatically flushed and closed when the method completes.

§Arguments
  • path - Path to the output file
§Example
use lib3mf::Model;

let mut model = Model::new();
// ... populate model with data ...

model.write_to_file("output.3mf")?;
Source

pub fn write_to_file_with_registry<P: AsRef<Path>>( self, path: P, registry: &ExtensionRegistry, ) -> Result<()>

Write a 3MF file to a file path with extension registry

This is a convenience method that creates a file and writes the 3MF data to it. Before writing, it calls pre_write() on all registered extension handlers. The file is automatically flushed and closed when the method completes.

§Arguments
  • path - Path to the output file
  • registry - Extension registry containing handlers that will be called before writing
§Example
use lib3mf::{Model, create_default_registry};

let mut model = Model::new();
// ... populate model with data ...

// Create registry with all standard extension handlers
let registry = create_default_registry();

model.write_to_file_with_registry("output.3mf", &registry)?;

Trait Implementations§

Source§

impl Clone for Model

Source§

fn clone(&self) -> Model

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 Model

Source§

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

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

impl Default for Model

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl Freeze for Model

§

impl RefUnwindSafe for Model

§

impl Send for Model

§

impl Sync for Model

§

impl Unpin for Model

§

impl UnsafeUnpin for Model

§

impl UnwindSafe for Model

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> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Converts Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Converts Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Converts &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Converts &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> DowncastSend for T
where T: Any + Send,

Source§

fn into_any_send(self: Box<T>) -> Box<dyn Any + Send>

Converts Box<Trait> (where Trait: DowncastSend) to Box<dyn Any + Send>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_sync(self: Box<T>) -> Box<dyn Any + Send + Sync>

Converts Box<Trait> (where Trait: DowncastSync) to Box<dyn Any + Send + Sync>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync>

Converts Arc<Trait> (where Trait: DowncastSync) to Arc<Any>, which can then be downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
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.