rust/bt-gatt: Update Error semantics Add From<&str> for convenience Mark as #[non_exhaustive] to minimize API churn Change-Id: Ife99fb490e5099d36a228fac440b1c6a4add67bd Reviewed-on: https://bluetooth-review.git.corp.google.com/c/bluetooth/+/1681 Reviewed-by: Dayeong Lee <dayeonglee@google.com>
diff --git a/rust/bt-gatt/src/types.rs b/rust/bt-gatt/src/types.rs index 84dae8a..cd052f2 100644 --- a/rust/bt-gatt/src/types.rs +++ b/rust/bt-gatt/src/types.rs
@@ -133,6 +133,7 @@ } #[derive(Error, Debug)] +#[non_exhaustive] pub enum Error { #[error("peer {0} was not recognized")] PeerNotRecognized(PeerId), @@ -148,6 +149,18 @@ Gatt(#[from] GattError), } +impl From<String> for Error { + fn from(value: String) -> Self { + Self::Other(Box::<dyn std::error::Error + Send + Sync>::from(value)) + } +} + +impl From<&str> for Error { + fn from(value: &str) -> Self { + String::from(value).into() + } +} + pub type Result<T> = core::result::Result<T, Error>; /// Handles are used as opaque identifiers for Characteristics and Descriptors.