pub struct Object { /* private fields */ }
Expand description
Owned object on the bus.
Object
s are created with Handle::create_object
and exist until either manually
destroyed or dropped. When an Object
is destroyed, all associated
Service
s 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
impl Object
sourcepub async fn new(
client: &Handle,
uuid: impl Into<ObjectUuid>,
) -> Result<Self, Error>
pub async fn new( client: &Handle, uuid: impl Into<ObjectUuid>, ) -> Result<Self, Error>
Creates a new object.
sourcepub fn client(&self) -> &Handle
pub fn client(&self) -> &Handle
Returns a handle to the client that was used to create the object.
sourcepub async fn destroy(&self) -> Result<(), Error>
pub async fn destroy(&self) -> Result<(), Error>
Destroys the object.
If the object has already been destroyed, Error::InvalidObject
is returned.
sourcepub async fn create_service(
&self,
uuid: impl Into<ServiceUuid>,
version: u32,
) -> Result<Service, Error>
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§
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more