pub struct ObjectDatabase { /* private fields */ }Expand description
A collection of BACnet objects, keyed by ObjectIdentifier.
Enforces BACnet Clause 12.11.12: Object_Name must be unique within a device. Maintains secondary indexes for O(1) name lookup and O(1) type lookup.
Implementations§
Source§impl ObjectDatabase
impl ObjectDatabase
Sourcepub fn add(&mut self, object: Box<dyn BACnetObject>) -> Result<(), Error>
pub fn add(&mut self, object: Box<dyn BACnetObject>) -> Result<(), Error>
Add an object to the database.
Returns Err if another object already has the same object_name()
(BACnet Clause 12.11.12 requires unique names within a device).
Replacing an object with the same OID is allowed (the old object is removed).
Sourcepub fn find_by_name(&self, name: &str) -> Option<&dyn BACnetObject>
pub fn find_by_name(&self, name: &str) -> Option<&dyn BACnetObject>
Look up an object by its name. O(1) via the name index.
Sourcepub fn check_name_available(
&self,
oid: &ObjectIdentifier,
new_name: &str,
) -> Result<(), Error>
pub fn check_name_available( &self, oid: &ObjectIdentifier, new_name: &str, ) -> Result<(), Error>
Check whether new_name is available for object oid.
Returns Ok(()) if the name is unused or already belongs to oid.
Returns Err(DUPLICATE_NAME) if another object owns the name.
Sourcepub fn update_name_index(&mut self, oid: &ObjectIdentifier)
pub fn update_name_index(&mut self, oid: &ObjectIdentifier)
Update the name index after a successful Object_Name write.
Call this after write_property(OBJECT_NAME, …) succeeds.
Sourcepub fn get(&self, oid: &ObjectIdentifier) -> Option<&dyn BACnetObject>
pub fn get(&self, oid: &ObjectIdentifier) -> Option<&dyn BACnetObject>
Get a shared reference to an object by identifier.
Sourcepub fn get_mut(
&mut self,
oid: &ObjectIdentifier,
) -> Option<&mut Box<dyn BACnetObject>>
pub fn get_mut( &mut self, oid: &ObjectIdentifier, ) -> Option<&mut Box<dyn BACnetObject>>
Get a mutable reference to an object by identifier.
Sourcepub fn remove(
&mut self,
oid: &ObjectIdentifier,
) -> Option<Box<dyn BACnetObject>>
pub fn remove( &mut self, oid: &ObjectIdentifier, ) -> Option<Box<dyn BACnetObject>>
Remove an object by identifier.
Sourcepub fn list_objects(&self) -> Vec<ObjectIdentifier>
pub fn list_objects(&self) -> Vec<ObjectIdentifier>
List all object identifiers in the database.
Sourcepub fn find_by_type(&self, object_type: ObjectType) -> Vec<ObjectIdentifier>
pub fn find_by_type(&self, object_type: ObjectType) -> Vec<ObjectIdentifier>
Find all objects of a given type.
Returns a Vec of ObjectIdentifiers whose object type matches object_type.
Useful for WhoHas, object enumeration, and similar queries.
Sourcepub fn iter_objects(
&self,
) -> impl Iterator<Item = (ObjectIdentifier, &dyn BACnetObject)>
pub fn iter_objects( &self, ) -> impl Iterator<Item = (ObjectIdentifier, &dyn BACnetObject)>
Iterate over all (ObjectIdentifier, &dyn BACnetObject) pairs.
Avoids the double-lookup pattern of list_objects() followed by get().