ResourceCollection

Struct ResourceCollection 

Source
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

Source

pub fn new() -> Self

Creates a new empty resource collection.

Source

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.).

Source

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.

Source

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.

Source

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.

Source

pub fn add_slice_stack(&mut self, stack: SliceStack) -> Result<()>

Source

pub fn add_volumetric_stack(&mut self, stack: VolumetricStack) -> Result<()>

Source

pub fn set_key_store(&mut self, store: KeyStore)

Source

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.

Source

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.

Source

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.

Source

pub fn get_slice_stack(&self, id: ResourceId) -> Option<&SliceStack>

Source

pub fn get_volumetric_stack(&self, id: ResourceId) -> Option<&VolumetricStack>

Source

pub fn add_texture_2d_group(&mut self, group: Texture2DGroup) -> Result<()>

Source

pub fn get_texture_2d_group(&self, id: ResourceId) -> Option<&Texture2DGroup>

Source

pub fn add_composite_materials( &mut self, group: CompositeMaterials, ) -> Result<()>

Source

pub fn get_composite_materials( &self, id: ResourceId, ) -> Option<&CompositeMaterials>

Source

pub fn add_multi_properties(&mut self, group: MultiProperties) -> Result<()>

Source

pub fn get_multi_properties(&self, id: ResourceId) -> Option<&MultiProperties>

Source

pub fn base_material_groups_count(&self) -> usize

Source

pub fn color_groups_count(&self) -> usize

Source

pub fn volumetric_stacks_count(&self) -> usize

Source

pub fn texture_2d_groups_count(&self) -> usize

Source

pub fn composite_materials_count(&self) -> usize

Source

pub fn multi_properties_count(&self) -> usize

Source

pub fn iter_objects(&self) -> impl Iterator<Item = &Object>

Returns an iterator over all objects in the collection.

Source

pub fn iter_objects_mut(&mut self) -> impl Iterator<Item = &mut Object>

Returns a mutable iterator over all objects in the collection.

Source

pub fn iter_base_materials(&self) -> impl Iterator<Item = &BaseMaterialsGroup>

Returns an iterator over all base material groups in the collection.

Source

pub fn iter_color_groups(&self) -> impl Iterator<Item = &ColorGroup>

Returns an iterator over all color groups in the collection.

Source

pub fn iter_textures(&self) -> impl Iterator<Item = &Texture2DGroup>

Returns an iterator over all texture 2D groups in the collection.

Source

pub fn iter_composite_materials( &self, ) -> impl Iterator<Item = &CompositeMaterials>

Returns an iterator over all composite material groups in the collection.

Source

pub fn iter_multi_properties(&self) -> impl Iterator<Item = &MultiProperties>

Returns an iterator over all multi-property groups in the collection.

Source

pub fn add_displacement_2d(&mut self, res: Displacement2D) -> Result<()>

Source

pub fn get_displacement_2d(&self, id: ResourceId) -> Option<&Displacement2D>

Source

pub fn displacement_2d_count(&self) -> usize

Source

pub fn iter_displacement_2d(&self) -> impl Iterator<Item = &Displacement2D>

Trait Implementations§

Source§

impl Clone for ResourceCollection

Source§

fn clone(&self) -> ResourceCollection

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 ResourceCollection

Source§

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

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

impl Default for ResourceCollection

Source§

fn default() -> ResourceCollection

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

impl<'de> Deserialize<'de> for ResourceCollection

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for ResourceCollection

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

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
§

impl<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

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> 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
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,