pub enum EventBody<'a> {
Owned(EventBodyOwned),
Borrowed(EventBodyBorrowed<'a>),
}
Expand description
Common event body that can be either owned or borrowed.
This is useful for APIs that can return either owned or borrowed event bodies.
Having this type allows to be generic over the event body type.
Variants§
Owned(EventBodyOwned)
Borrowed(EventBodyBorrowed<'a>)
Implementations§
Source§impl<'a> EventBody<'_>
impl<'a> EventBody<'_>
Sourcepub fn as_owned(&self) -> Result<EventBodyOwned, AtspiError>
pub fn as_owned(&self) -> Result<EventBodyOwned, AtspiError>
Non-consuming conversion to an owned event body.
Does cloning.
§Errors
The borrowed variant will error if the following conditions are met:
- the
any_data
field contains an [std::os::fd::OwnedFd
] type, and - the maximum number of open files for the process is exceeded.
Sourcepub fn into_owned(self) -> Result<EventBodyOwned, AtspiError>
pub fn into_owned(self) -> Result<EventBodyOwned, AtspiError>
Consuming conversion to an owned event body.
Does cloning.
§Errors
The borrowed variant will error if the following conditions are met:
- the
any_data
field contains an [std::os::fd::OwnedFd
] type, and - the maximum number of open files for the process is exceeded.
Sourcepub fn kind(&'a self) -> &'a str
pub fn kind(&'a self) -> &'a str
The kind
field as &str
.
With both variants, this method returns a reference to the kind
field.
Sourcepub fn take_kind(&mut self) -> String
pub fn take_kind(&mut self) -> String
Take or convert the kind
field as String
.
With the owned variant, this method takes the kind
field and replaces it with an empty string.
With the borrowed variant, this method clones and allocates the kind
field.
pub fn detail1(&self) -> i32
pub fn detail2(&self) -> i32
Sourcepub fn any_data(&'a self) -> &'a Value<'a>
pub fn any_data(&'a self) -> &'a Value<'a>
The any_data
field as &Value
.
With both variants, this method returns a reference to the any_data
field.
Sourcepub fn take_any_data(&mut self) -> OwnedValue
pub fn take_any_data(&mut self) -> OwnedValue
Take or convert the any_data
field as OwnedValue
.
With the owned variant, this method takes the any_data
field and replaces it with a default value.
As Value
does not have a default value, we will replace with 0_u32
, a nbon-allocating value.
With the borrowed variant, this method clones and allocates the any_data
field.
§Panics
This method will panic if the any_data
field contains an [std::os::fd::OwnedFd
] type, and
the maximum number of open files for the process is exceeded.
None of the types in crate::events
use [std::os::fd::OwnedFd
].
Events on the AT-SPI bus could, theoretically send a file descriptor, but nothing in the current
specification describes that.