Struct design_pattern_examples_rust::flyweight::flyweight_bigresource_manager::BigResourceManager
source · pub struct BigResourceManager {
resources: Vec<BigResource>,
}
Expand description
Represents a list of instances of the BigResource struct. Use the add_resource() method to add a BigResource instance to the list (and also take ownership of the BigResource instance). Call get_resource() with the ID of the resource to get the BigResource instance.
Fields§
§resources: Vec<BigResource>
Implementations§
source§impl BigResourceManager
impl BigResourceManager
sourcepub fn new() -> BigResourceManager
pub fn new() -> BigResourceManager
sourcepub fn add_resource(&mut self, resource: BigResource) -> usize
pub fn add_resource(&mut self, resource: BigResource) -> usize
Add a BigResource object to the list of big resources. The list takes ownership of the BigResource object.
Parameters
-
resource
The BigResource to store in the manager.
Returns
Returns the “id” of the resource so it can be used to access the resource later on. Technically, the ID is actually the index where the BigResource instance appears in the internal list.
sourcepub fn get_resource(&self, resource_id: usize) -> Option<&BigResource>
pub fn get_resource(&self, resource_id: usize) -> Option<&BigResource>
Retrieve the requested big resource.
Parameters
-
resource_id
The ID of the resource to retrieve.
Returns
Returns Some(&BigResource) if the resource exists; otherwise, returns None.