Fix downcast_to_device

This commit is contained in:
Lucy 2022-01-13 14:32:52 -05:00
parent 02c744a119
commit 54a9f4d6f3
No known key found for this signature in database
GPG key ID: EBC517FAD666BBF1

View file

@ -56,30 +56,30 @@ impl<'a> Device<'a> {
self.0.device_type().await.map(DeviceType::from)
}
pub async fn downcast_to_device(&'a self) -> Result<SpecificDevice<'a>> {
pub async fn downcast_to_device(&'a self) -> Result<Option<SpecificDevice<'a>>> {
match self.device_type().await? {
DeviceType::Bluetooth => Ok(SpecificDevice::Bluetooth(
DeviceType::Bluetooth => Ok(Some(SpecificDevice::Bluetooth(
BluetoothDeviceProxy::builder(self.0.connection())
.path(self.0.path())?
.build()
.await?
.into(),
)),
DeviceType::Ethernet => Ok(SpecificDevice::Wired(
))),
DeviceType::Ethernet => Ok(Some(SpecificDevice::Wired(
WiredDeviceProxy::builder(self.0.connection())
.path(self.0.path())?
.build()
.await?
.into(),
)),
DeviceType::Wifi => Ok(SpecificDevice::Wireless(
))),
DeviceType::Wifi => Ok(Some(SpecificDevice::Wireless(
WirelessDeviceProxy::builder(self.0.connection())
.path(self.0.path())?
.build()
.await?
.into(),
)),
_ => unimplemented!(),
))),
_ => Ok(None),
}
}