pub struct ResourceCollection {
pub key_store: Option<KeyStore>,
/* private fields */
}Expand description
Central registry for all resources in a 3MF model.
The ResourceCollection manages all reusable resources including objects,
materials, textures, and extension-specific resources. It enforces the global
ID namespace requirement: each ResourceId can only be used once across
all resource types.
Resources are stored in separate HashMap<ResourceId, T> collections internally,
allowing efficient lookup by ID.
§Examples
use lib3mf_core::model::{ResourceCollection, Object, ResourceId, Geometry, Mesh, ObjectType};
let mut resources = ResourceCollection::new();
let obj = Object {
id: ResourceId(1),
object_type: ObjectType::Model,
name: None,
part_number: None,
uuid: None,
pid: None,
pindex: None,
thumbnail: None,
geometry: Geometry::Mesh(Mesh::default()),
};
resources.add_object(obj).expect("Failed to add object");
assert!(resources.exists(ResourceId(1)));Fields§
§key_store: Option<KeyStore>Optional Secure Content key store for this model (at most one per model).
Implementations§
Source§impl ResourceCollection
impl ResourceCollection
Sourcepub fn exists(&self, id: ResourceId) -> bool
pub fn exists(&self, id: ResourceId) -> bool
Checks if a resource with the given ID exists in any resource type.
Returns true if the ID is used by any resource (object, material, texture, etc.).
Sourcepub fn add_object(&mut self, object: Object) -> Result<()>
pub fn add_object(&mut self, object: Object) -> Result<()>
Adds an object to the collection.
§Errors
Returns Lib3mfError::Validation if a resource with the same ID already exists.
Sourcepub fn add_base_materials(&mut self, group: BaseMaterialsGroup) -> Result<()>
pub fn add_base_materials(&mut self, group: BaseMaterialsGroup) -> Result<()>
Adds a base materials group to the collection.
§Errors
Returns Lib3mfError::Validation if a resource with the same ID already exists.
Sourcepub fn add_color_group(&mut self, group: ColorGroup) -> Result<()>
pub fn add_color_group(&mut self, group: ColorGroup) -> Result<()>
Adds a color group to the collection.
§Errors
Returns Lib3mfError::Validation if a resource with the same ID already exists.
Sourcepub fn add_slice_stack(&mut self, stack: SliceStack) -> Result<()>
pub fn add_slice_stack(&mut self, stack: SliceStack) -> Result<()>
Adds a slice stack resource to the collection.
§Errors
Returns Lib3mfError::Validation if a resource with the same ID already exists.
Sourcepub fn add_volumetric_stack(&mut self, stack: VolumetricStack) -> Result<()>
pub fn add_volumetric_stack(&mut self, stack: VolumetricStack) -> Result<()>
Adds a volumetric stack resource to the collection.
§Errors
Returns Lib3mfError::Validation if a resource with the same ID already exists.
Sourcepub fn set_key_store(&mut self, store: KeyStore)
pub fn set_key_store(&mut self, store: KeyStore)
Sets the Secure Content key store for this model (replaces any existing key store).
Sourcepub fn get_object(&self, id: ResourceId) -> Option<&Object>
pub fn get_object(&self, id: ResourceId) -> Option<&Object>
Retrieves an object by its ID.
Returns None if no object with the given ID exists.
Sourcepub fn get_base_materials(&self, id: ResourceId) -> Option<&BaseMaterialsGroup>
pub fn get_base_materials(&self, id: ResourceId) -> Option<&BaseMaterialsGroup>
Retrieves a base materials group by its ID.
Returns None if no base materials group with the given ID exists.
Sourcepub fn get_color_group(&self, id: ResourceId) -> Option<&ColorGroup>
pub fn get_color_group(&self, id: ResourceId) -> Option<&ColorGroup>
Retrieves a color group by its ID.
Returns None if no color group with the given ID exists.
Sourcepub fn get_slice_stack(&self, id: ResourceId) -> Option<&SliceStack>
pub fn get_slice_stack(&self, id: ResourceId) -> Option<&SliceStack>
Retrieves a slice stack by its ID.
Returns None if no slice stack with the given ID exists.
Sourcepub fn get_volumetric_stack(&self, id: ResourceId) -> Option<&VolumetricStack>
pub fn get_volumetric_stack(&self, id: ResourceId) -> Option<&VolumetricStack>
Retrieves a volumetric stack by its ID.
Returns None if no volumetric stack with the given ID exists.
Sourcepub fn add_texture_2d(&mut self, texture: Texture2D) -> Result<()>
pub fn add_texture_2d(&mut self, texture: Texture2D) -> Result<()>
Adds a 2D texture resource to the collection.
§Errors
Returns Lib3mfError::Validation if a resource with the same ID already exists.
Sourcepub fn add_texture_2d_group(&mut self, group: Texture2DGroup) -> Result<()>
pub fn add_texture_2d_group(&mut self, group: Texture2DGroup) -> Result<()>
Adds a 2D texture coordinate group to the collection.
§Errors
Returns Lib3mfError::Validation if a resource with the same ID already exists.
Sourcepub fn get_texture_2d_group(&self, id: ResourceId) -> Option<&Texture2DGroup>
pub fn get_texture_2d_group(&self, id: ResourceId) -> Option<&Texture2DGroup>
Retrieves a 2D texture coordinate group by its ID.
Returns None if no texture 2D group with the given ID exists.
Sourcepub fn add_composite_materials(
&mut self,
group: CompositeMaterials,
) -> Result<()>
pub fn add_composite_materials( &mut self, group: CompositeMaterials, ) -> Result<()>
Adds a composite materials group to the collection.
§Errors
Returns Lib3mfError::Validation if a resource with the same ID already exists.
Sourcepub fn get_composite_materials(
&self,
id: ResourceId,
) -> Option<&CompositeMaterials>
pub fn get_composite_materials( &self, id: ResourceId, ) -> Option<&CompositeMaterials>
Retrieves a composite materials group by its ID.
Returns None if no composite materials group with the given ID exists.
Sourcepub fn add_multi_properties(&mut self, group: MultiProperties) -> Result<()>
pub fn add_multi_properties(&mut self, group: MultiProperties) -> Result<()>
Adds a multi-properties group to the collection.
§Errors
Returns Lib3mfError::Validation if a resource with the same ID already exists.
Sourcepub fn get_multi_properties(&self, id: ResourceId) -> Option<&MultiProperties>
pub fn get_multi_properties(&self, id: ResourceId) -> Option<&MultiProperties>
Retrieves a multi-properties group by its ID.
Returns None if no multi-properties group with the given ID exists.
Sourcepub fn base_material_groups_count(&self) -> usize
pub fn base_material_groups_count(&self) -> usize
Returns the number of base material groups in the collection.
Sourcepub fn color_groups_count(&self) -> usize
pub fn color_groups_count(&self) -> usize
Returns the number of color groups in the collection.
Sourcepub fn volumetric_stacks_count(&self) -> usize
pub fn volumetric_stacks_count(&self) -> usize
Returns the number of volumetric stacks in the collection.
Sourcepub fn texture_2d_groups_count(&self) -> usize
pub fn texture_2d_groups_count(&self) -> usize
Returns the number of 2D texture coordinate groups in the collection.
Sourcepub fn composite_materials_count(&self) -> usize
pub fn composite_materials_count(&self) -> usize
Returns the number of composite materials groups in the collection.
Sourcepub fn multi_properties_count(&self) -> usize
pub fn multi_properties_count(&self) -> usize
Returns the number of multi-properties groups in the collection.
Sourcepub fn iter_objects(&self) -> impl Iterator<Item = &Object>
pub fn iter_objects(&self) -> impl Iterator<Item = &Object>
Returns an iterator over all objects in the collection.
Sourcepub fn iter_objects_mut(&mut self) -> impl Iterator<Item = &mut Object>
pub fn iter_objects_mut(&mut self) -> impl Iterator<Item = &mut Object>
Returns a mutable iterator over all objects in the collection.
Sourcepub fn iter_base_materials(&self) -> impl Iterator<Item = &BaseMaterialsGroup>
pub fn iter_base_materials(&self) -> impl Iterator<Item = &BaseMaterialsGroup>
Returns an iterator over all base material groups in the collection.
Sourcepub fn iter_color_groups(&self) -> impl Iterator<Item = &ColorGroup>
pub fn iter_color_groups(&self) -> impl Iterator<Item = &ColorGroup>
Returns an iterator over all color groups in the collection.
Sourcepub fn iter_textures(&self) -> impl Iterator<Item = &Texture2DGroup>
pub fn iter_textures(&self) -> impl Iterator<Item = &Texture2DGroup>
Returns an iterator over all texture 2D groups in the collection.
Sourcepub fn iter_composite_materials(
&self,
) -> impl Iterator<Item = &CompositeMaterials>
pub fn iter_composite_materials( &self, ) -> impl Iterator<Item = &CompositeMaterials>
Returns an iterator over all composite material groups in the collection.
Sourcepub fn iter_multi_properties(&self) -> impl Iterator<Item = &MultiProperties>
pub fn iter_multi_properties(&self) -> impl Iterator<Item = &MultiProperties>
Returns an iterator over all multi-property groups in the collection.
Sourcepub fn add_displacement_2d(&mut self, res: Displacement2D) -> Result<()>
pub fn add_displacement_2d(&mut self, res: Displacement2D) -> Result<()>
Adds a 2D displacement texture resource to the collection.
§Errors
Returns Lib3mfError::Validation if a resource with the same ID already exists.
Sourcepub fn get_displacement_2d(&self, id: ResourceId) -> Option<&Displacement2D>
pub fn get_displacement_2d(&self, id: ResourceId) -> Option<&Displacement2D>
Retrieves a 2D displacement texture resource by its ID.
Returns None if no displacement 2D resource with the given ID exists.
Sourcepub fn displacement_2d_count(&self) -> usize
pub fn displacement_2d_count(&self) -> usize
Returns the number of 2D displacement texture resources in the collection.
Sourcepub fn iter_displacement_2d(&self) -> impl Iterator<Item = &Displacement2D>
pub fn iter_displacement_2d(&self) -> impl Iterator<Item = &Displacement2D>
Returns an iterator over all 2D displacement texture resources in the collection.
Sourcepub fn iter_texture_2d(&self) -> impl Iterator<Item = &Texture2D>
pub fn iter_texture_2d(&self) -> impl Iterator<Item = &Texture2D>
Returns an iterator over all Texture2D resources in the collection.
Sourcepub fn iter_slice_stacks(&self) -> impl Iterator<Item = &SliceStack>
pub fn iter_slice_stacks(&self) -> impl Iterator<Item = &SliceStack>
Returns an iterator over all slice stacks in the collection.
Sourcepub fn iter_volumetric_stacks(&self) -> impl Iterator<Item = &VolumetricStack>
pub fn iter_volumetric_stacks(&self) -> impl Iterator<Item = &VolumetricStack>
Returns an iterator over all volumetric stacks in the collection.
Trait Implementations§
Source§impl Clone for ResourceCollection
impl Clone for ResourceCollection
Source§fn clone(&self) -> ResourceCollection
fn clone(&self) -> ResourceCollection
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for ResourceCollection
impl Debug for ResourceCollection
Source§impl Default for ResourceCollection
impl Default for ResourceCollection
Source§fn default() -> ResourceCollection
fn default() -> ResourceCollection
Source§impl<'de> Deserialize<'de> for ResourceCollection
impl<'de> Deserialize<'de> for ResourceCollection
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Auto Trait Implementations§
impl Freeze for ResourceCollection
impl RefUnwindSafe for ResourceCollection
impl Send for ResourceCollection
impl Sync for ResourceCollection
impl Unpin for ResourceCollection
impl UnsafeUnpin for ResourceCollection
impl UnwindSafe for ResourceCollection
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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> 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