Skip to main content

ObjectDatabase

Struct ObjectDatabase 

Source
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

Source

pub fn new() -> Self

Create an empty database.

Source

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

Source

pub fn find_by_name(&self, name: &str) -> Option<&dyn BACnetObject>

Look up an object by its name. O(1) via the name index.

Source

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.

Source

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.

Source

pub fn get(&self, oid: &ObjectIdentifier) -> Option<&dyn BACnetObject>

Get a shared reference to an object by identifier.

Source

pub fn get_mut( &mut self, oid: &ObjectIdentifier, ) -> Option<&mut Box<dyn BACnetObject>>

Get a mutable reference to an object by identifier.

Source

pub fn remove( &mut self, oid: &ObjectIdentifier, ) -> Option<Box<dyn BACnetObject>>

Remove an object by identifier.

Source

pub fn list_objects(&self) -> Vec<ObjectIdentifier>

List all object identifiers in the database.

Source

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.

Source

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

Source

pub fn len(&self) -> usize

Number of objects in the database.

Source

pub fn is_empty(&self) -> bool

Whether the database is empty.

Trait Implementations§

Source§

impl Default for ObjectDatabase

Source§

fn default() -> Self

Returns the “default value” for a type. 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
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> 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, 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.