Struct aldrin::Object

source ·
pub struct Object { /* private fields */ }
Expand description

Owned object on the bus.

Objects are created with Handle::create_object and exist until either manually destroyed or dropped. When an Object is destroyed, all associated Services will be destroyed as well. At runtime, every valid Object is uniquely identified by an ObjectId on the bus.

Object holds an internal Handle and will thus prevent the Client from shutting down automatically. The Handle is released when the Object is dropped.

§Examples

use aldrin::core::ObjectUuid;
use uuid::uuid;

const OBJECT2_UUID: ObjectUuid = ObjectUuid(uuid!("6173e119-8066-4776-989b-145a5f16ed4c"));

// Create an object with a random UUID:
let object1 = handle.create_object(ObjectUuid::new_v4()).await?;

// Destroy object1 explicitly:
object1.destroy().await?;

{
    // Create an object with a fixed UUID:
    let object2 = handle.create_object(OBJECT2_UUID).await?;

    // object2 is destroyed implicitly when it falls out of scope and is dropped.
}

Implementations§

source§

impl Object

source

pub fn id(&self) -> ObjectId

Returns the id of the object.

source

pub fn handle(&self) -> &Handle

Returns a handle to the client that was used to create the object.

source

pub async fn destroy(&self) -> Result<(), Error>

Destroys the object.

If the object has already been destroyed, Error::InvalidObject is returned.

source

pub async fn create_service( &self, uuid: impl Into<ServiceUuid>, version: u32 ) -> Result<Service, Error>

Creates a service on the object.

The uuid must not yet exists on this Object, or else Error::DuplicateService will be returned.

§Examples
use aldrin::Error;
use aldrin::core::{ObjectUuid, ServiceUuid};
use uuid::uuid;

const MY_SERVICE_UUID: ServiceUuid = ServiceUuid(uuid!("800b47a1-3882-4601-9155-e18c654476cc"));

let object = handle.create_object(ObjectUuid::new_v4()).await?;

// Create a service:
let service = object.create_service(MY_SERVICE_UUID, 0).await?;

// Trying to create the same service on the same object again will cause an error:
assert_eq!(
    object.create_service(MY_SERVICE_UUID, 0).await.unwrap_err(),
    Error::DuplicateService,
);

Trait Implementations§

source§

impl Debug for Object

source§

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

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

impl Drop for Object

source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl Freeze for Object

§

impl !RefUnwindSafe for Object

§

impl Send for Object

§

impl Sync for Object

§

impl Unpin for Object

§

impl !UnwindSafe for Object

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

§

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

§

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.