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: StringUnit of measurement (e.g., “millimeter”, “inch”)
xmlns: StringXML 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: ResourcesResources (objects, materials)
build: BuildBuild specification
secure_content: Option<SecureContentInfo>Secure content information (if secure content extension is used)
Implementations§
Source§impl Model
impl Model
Sourcepub fn from_reader<R: Read + Seek>(reader: R) -> Result<Self>
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)?;Sourcepub fn from_reader_with_config<R: Read + Seek>(
reader: R,
config: ParserConfig,
) -> Result<Self>
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 dataconfig- 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)?;Sourcepub fn read_thumbnail<R: Read + Seek>(reader: R) -> Result<Option<Vec<u8>>>
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)?;
}Sourcepub fn to_writer<W: Write + Seek>(self, writer: W) -> Result<W>
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)?;Sourcepub fn to_writer_with_registry<W: Write + Seek>(
self,
writer: W,
registry: &ExtensionRegistry,
) -> Result<W>
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 toregistry- 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, ®istry)?;Sourcepub fn write_to_file<P: AsRef<Path>>(self, path: P) -> Result<()>
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")?;Sourcepub fn write_to_file_with_registry<P: AsRef<Path>>(
self,
path: P,
registry: &ExtensionRegistry,
) -> Result<()>
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 fileregistry- 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", ®istry)?;Trait Implementations§
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> 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> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
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>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
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)
fn as_any(&self) -> &(dyn Any + 'static)
&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)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&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
impl<T> DowncastSend for T
Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
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 moreSource§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.