Skip to content

Commit 85c94b6

Browse files
committed
Convert Error to std::io::Error.
1 parent 0468f1f commit 85c94b6

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

bluer/src/lib.rs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -723,6 +723,43 @@ impl From<InvalidAddress> for Error {
723723
}
724724
}
725725

726+
#[cfg(feature = "bluetoothd")]
727+
impl From<Error> for std::io::Error {
728+
fn from(err: Error) -> Self {
729+
use std::io::ErrorKind as E;
730+
let kind = match err.kind {
731+
ErrorKind::AlreadyConnected => E::AlreadyExists,
732+
ErrorKind::AlreadyExists => E::AlreadyExists,
733+
ErrorKind::AuthenticationCanceled => E::PermissionDenied,
734+
ErrorKind::AuthenticationFailed => E::PermissionDenied,
735+
ErrorKind::AuthenticationRejected => E::PermissionDenied,
736+
ErrorKind::AuthenticationTimeout => E::PermissionDenied,
737+
ErrorKind::ConnectionAttemptFailed => E::ConnectionRefused,
738+
ErrorKind::DoesNotExist => E::NotFound,
739+
ErrorKind::Failed => E::Other,
740+
ErrorKind::InProgress => E::Other,
741+
ErrorKind::InvalidArguments => E::InvalidInput,
742+
ErrorKind::InvalidLength => E::InvalidData,
743+
ErrorKind::NotAvailable => E::NotFound,
744+
ErrorKind::NotAuthorized => E::PermissionDenied,
745+
ErrorKind::NotReady => E::Other,
746+
ErrorKind::NotSupported => E::Unsupported,
747+
ErrorKind::NotPermitted => E::PermissionDenied,
748+
ErrorKind::InvalidOffset => E::InvalidInput,
749+
ErrorKind::InvalidAddress(_) => E::InvalidInput,
750+
ErrorKind::InvalidName(_) => E::InvalidInput,
751+
ErrorKind::ServicesUnresolved => E::Other,
752+
ErrorKind::NotRegistered => E::Other,
753+
ErrorKind::NotificationSessionStopped => E::ConnectionReset,
754+
ErrorKind::IndicationUnconfirmed => E::TimedOut,
755+
ErrorKind::NotFound => E::NotFound,
756+
ErrorKind::Internal(InternalErrorKind::Io(err)) => err,
757+
ErrorKind::Internal(_) => E::Other,
758+
};
759+
std::io::Error::new(kind, err)
760+
}
761+
}
762+
726763
#[cfg(all(feature = "bluetoothd", feature = "serde"))]
727764
mod io_errorkind_serde {
728765
pub fn serialize<S>(_kind: &std::io::ErrorKind, ser: S) -> Result<S::Ok, S::Error>

0 commit comments

Comments
 (0)