diff --git a/bindings/matrix-sdk-ffi/src/error.rs b/bindings/matrix-sdk-ffi/src/error.rs new file mode 100644 index 000000000..5209d06db --- /dev/null +++ b/bindings/matrix-sdk-ffi/src/error.rs @@ -0,0 +1,43 @@ +use matrix_sdk::{self, encryption::CryptoStoreError, HttpError, IdParseError}; + +#[derive(thiserror::Error, Debug)] +pub enum ClientError { + #[error("client error: {msg}")] + Generic { msg: String }, +} + +impl From for ClientError { + fn from(e: anyhow::Error) -> ClientError { + ClientError::Generic { msg: e.to_string() } + } +} + +impl From for ClientError { + fn from(e: matrix_sdk::Error) -> Self { + anyhow::Error::from(e).into() + } +} + +impl From for ClientError { + fn from(e: CryptoStoreError) -> Self { + anyhow::Error::from(e).into() + } +} + +impl From for ClientError { + fn from(e: HttpError) -> Self { + anyhow::Error::from(e).into() + } +} + +impl From for ClientError { + fn from(e: IdParseError) -> Self { + anyhow::Error::from(e).into() + } +} + +impl From for ClientError { + fn from(e: serde_json::Error) -> Self { + anyhow::Error::from(e).into() + } +} diff --git a/bindings/matrix-sdk-ffi/src/lib.rs b/bindings/matrix-sdk-ffi/src/lib.rs index e1ebb843f..f094b85e8 100644 --- a/bindings/matrix-sdk-ffi/src/lib.rs +++ b/bindings/matrix-sdk-ffi/src/lib.rs @@ -25,6 +25,7 @@ mod platform; pub mod authentication_service; pub mod client; pub mod client_builder; +mod error; mod helpers; pub mod notification_service; pub mod room; @@ -34,12 +35,12 @@ pub mod sliding_sync; pub mod timeline; pub mod tracing; -use client::Client; -use client_builder::ClientBuilder; -use matrix_sdk::{encryption::CryptoStoreError, HttpError, IdParseError}; use once_cell::sync::Lazy; use tokio::runtime::Runtime; +// Re-exports for more convenient use inside other submodules +use self::{client::Client, client_builder::ClientBuilder, error::ClientError}; + pub static RUNTIME: Lazy = Lazy::new(|| Runtime::new().expect("Can't start Tokio runtime")); @@ -47,54 +48,11 @@ pub use matrix_sdk::{ room::timeline::PaginationOutcome, ruma::{api::client::account::register, UserId}, }; +pub use platform::*; pub use self::{ authentication_service::*, client::*, notification_service::*, room::*, room_member::*, session_verification::*, sliding_sync::*, timeline::*, tracing::*, }; -#[derive(thiserror::Error, Debug)] -pub enum ClientError { - #[error("client error: {msg}")] - Generic { msg: String }, -} - -impl From for ClientError { - fn from(e: anyhow::Error) -> ClientError { - ClientError::Generic { msg: e.to_string() } - } -} - -impl From for ClientError { - fn from(e: matrix_sdk::Error) -> Self { - anyhow::Error::from(e).into() - } -} - -impl From for ClientError { - fn from(e: CryptoStoreError) -> Self { - anyhow::Error::from(e).into() - } -} - -impl From for ClientError { - fn from(e: HttpError) -> Self { - anyhow::Error::from(e).into() - } -} - -impl From for ClientError { - fn from(e: IdParseError) -> Self { - anyhow::Error::from(e).into() - } -} - -impl From for ClientError { - fn from(e: serde_json::Error) -> Self { - anyhow::Error::from(e).into() - } -} - -pub use platform::*; - uniffi::include_scaffolding!("api");