Expose underlying platform specific implemenations (#660)

* expose underlying platform specific implemenations

* add doc to Inner enums

* fix: return `&mut` from `as_inner_mut`
This commit is contained in:
Rodrigo Batista de Moraes 2022-04-25 22:11:14 -03:00 • committed by GitHub
parent a420316e30
commit 8d164ed585
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -85,28 +85,32 @@ macro_rules! impl_platform_host {
)*
}
enum DeviceInner {
/// Contains a platform specific `Device` implementation.
pub enum DeviceInner {
$(
$(#[cfg($feat)])?
$HostVariant(crate::host::$host_mod::Device),
)*
}
enum DevicesInner {
/// Contains a platform specific `Devices` implementation.
pub enum DevicesInner {
$(
$(#[cfg($feat)])?
$HostVariant(crate::host::$host_mod::Devices),
)*
}
enum HostInner {
/// Contains a platform specific `Host` implementation.
pub enum HostInner {
$(
$(#[cfg($feat)])?
$HostVariant(crate::host::$host_mod::Host),
)*
}
enum StreamInner {
/// Contains a platform specific `Stream` implementation.
pub enum StreamInner {
$(
$(#[cfg($feat)])?
$HostVariant(crate::host::$host_mod::Stream),
@ -138,6 +142,44 @@ macro_rules! impl_platform_host {
}
}
impl Devices {
/// Returns a reference to the underlying platform specific implementation of this
/// `Devices`.
pub fn as_inner(&self) -> &DevicesInner {
&self.0
}
/// Returns a mutable reference to the underlying platform specific implementation of
/// this `Devices`.
pub fn as_inner_mut(&mut self) -> &mut DevicesInner {
&mut self.0
}
/// Returns the underlying platform specific implementation of this `Devices`.
pub fn into_inner(self) -> DevicesInner {
self.0
}
}
impl Device {
/// Returns a reference to the underlying platform specific implementation of this
/// `Device`.
pub fn as_inner(&self) -> &DeviceInner {
&self.0
}
/// Returns a mutable reference to the underlying platform specific implementation of
/// this `Device`.
pub fn as_inner_mut(&mut self) -> &mut DeviceInner {
&mut self.0
}
/// Returns the underlying platform specific implementation of this `Device`.
pub fn into_inner(self) -> DeviceInner {
self.0
}
}
impl Host {
/// The unique identifier associated with this host.
pub fn id(&self) -> HostId {
@ -148,6 +190,42 @@ macro_rules! impl_platform_host {
)*
}
}
/// Returns a reference to the underlying platform specific implementation of this
/// `Host`.
pub fn as_inner(&self) -> &HostInner {
&self.0
}
/// Returns a mutable reference to the underlying platform specific implementation of
/// this `Host`.
pub fn as_inner_mut(&mut self) -> &mut HostInner {
&mut self.0
}
/// Returns the underlying platform specific implementation of this `Host`.
pub fn into_inner(self) -> HostInner {
self.0
}
}
impl Stream {
/// Returns a reference to the underlying platform specific implementation of this
/// `Stream`.
pub fn as_inner(&self) -> &StreamInner {
&self.0
}
/// Returns a mutable reference to the underlying platform specific implementation of
/// this `Stream`.
pub fn as_inner_mut(&mut self) -> &mut StreamInner {
&mut self.0
}
/// Returns the underlying platform specific implementation of this `Stream`.
pub fn into_inner(self) -> StreamInner {
self.0
}
}
impl Iterator for Devices {