Module objects

Module objects 

Source
Expand description

§Module providing addressable object support and a manager for them

Each addressable object can be identified using an object ID. The system object trait also allows storing these objects into the object manager. They can then be retrieved and casted back to a known type using the object ID.

§Examples

use std::any::Any;
use std::error::Error;
use satrs_core::objects::{ManagedSystemObject, ObjectId, ObjectManager, SystemObject};

struct ExampleSysObj {
    id: ObjectId,
    dummy: u32,
    was_initialized: bool,
}

impl ExampleSysObj {
    fn new(id: ObjectId, dummy: u32) -> ExampleSysObj {
        ExampleSysObj {
            id,
            dummy,
            was_initialized: false,
        }
    }
}

impl SystemObject for ExampleSysObj {
    type Error = ();
    fn get_object_id(&self) -> &ObjectId {
        &self.id
    }

    fn initialize(&mut self) -> Result<(), Self::Error> {
        self.was_initialized = true;
        Ok(())
    }
}

impl ManagedSystemObject for ExampleSysObj {}

 let mut obj_manager = ObjectManager::default();
 let obj_id = ObjectId { id: 0, name: "Example 0"};
 let example_obj = ExampleSysObj::new(obj_id, 42);
 obj_manager.insert(Box::new(example_obj));
 let obj_back_casted: Option<&ExampleSysObj> = obj_manager.get_ref(&obj_id);
 let example_obj = obj_back_casted.unwrap();
 assert_eq!(example_obj.id, obj_id);
 assert_eq!(example_obj.dummy, 42);

Re-exports§

pub use alloc_mod::*;alloc

Modules§

alloc_modalloc

Structs§

ObjectId