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>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.
pub fn add_slice_stack(&mut self, stack: SliceStack) -> Result<()>
pub fn add_volumetric_stack(&mut self, stack: VolumetricStack) -> Result<()>
pub fn set_key_store(&mut self, store: KeyStore)
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.
pub fn get_slice_stack(&self, id: ResourceId) -> Option<&SliceStack>
pub fn get_volumetric_stack(&self, id: ResourceId) -> Option<&VolumetricStack>
pub fn add_texture_2d_group(&mut self, group: Texture2DGroup) -> Result<()>
pub fn get_texture_2d_group(&self, id: ResourceId) -> Option<&Texture2DGroup>
pub fn add_composite_materials( &mut self, group: CompositeMaterials, ) -> Result<()>
pub fn get_composite_materials( &self, id: ResourceId, ) -> Option<&CompositeMaterials>
pub fn add_multi_properties(&mut self, group: MultiProperties) -> Result<()>
pub fn get_multi_properties(&self, id: ResourceId) -> Option<&MultiProperties>
pub fn base_material_groups_count(&self) -> usize
pub fn color_groups_count(&self) -> usize
pub fn volumetric_stacks_count(&self) -> usize
pub fn texture_2d_groups_count(&self) -> usize
pub fn composite_materials_count(&self) -> usize
pub fn multi_properties_count(&self) -> usize
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.
pub fn add_displacement_2d(&mut self, res: Displacement2D) -> Result<()>
pub fn get_displacement_2d(&self, id: ResourceId) -> Option<&Displacement2D>
pub fn displacement_2d_count(&self) -> usize
pub fn iter_displacement_2d(&self) -> impl Iterator<Item = &Displacement2D>
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 UnwindSafe for ResourceCollection
Blanket Implementations§
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§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