lemon_bugsnag_rs 0.1.2

A library for interacting with the BugSnag error-reporting and sessions APIs.
Documentation
/// Trait to be implemented for asynchronous backend clients. For example, a
/// client based on the async_impl components in Reqwest. See
/// [ReqwestErrorAsync](crate::error::reqwest::client::non_blocking::ReqwestErrorAsync).
///
/// # Example
/// ```
/// // This example requires the async feature to be enabled.
///
/// use lemon_bugsnag_rs::common::traits::client_trait_async::ClientTraitAsync;
/// use lemon_bugsnag_rs::common::error::Error;
///
/// struct MyAsyncClient {}
/// struct MyAsyncResponse {}
///
/// #[async_trait::async_trait]
/// impl ClientTraitAsync for MyAsyncClient {
///     type Response = MyAsyncResponse;
///     type Error = Error;
///
///     async fn send(&mut self) -> Result<Self::Response, Self::Error> {
///         // For purposes of this example, BackendClient::send() is a
///         // function that returns Result<MyAsyncResponse, BackendError>,
///         // where From<BackendError> has been implemented for Self::Error.
///         # #[cfg(norun)]
///         let result = BackendClient::send();
///         # let result: Result<Self::Response, Self::Error> = Ok(MyAsyncResponse {});
///         Ok(result?)
///     }
/// }
/// ```
#[async_trait::async_trait]
pub trait ClientTraitAsync {
    /// The response type returned by the backend client.
    ///
    /// ```
    /// // This example requires the async feature.
    /// // This example requires the reqwest feature.
    ///
    /// use lemon_bugsnag_rs::common::traits::client_trait_async::ClientTraitAsync;
    /// use reqwest::Response;
    ///
    /// struct MyClient {}
    /// # #[cfg(feature = "reqwest")]
    /// # {
    ///
    /// # #[cfg(norun)]
    /// impl ClientTraitAsync for MyClient {
    ///     type Response = Response;
    /// #    type Error = lemon_bugsnag_rs::common::error::Error;
    ///
    ///     // ... implement send()
    /// }
    /// # }
    /// ```
    type Response;
    /// The error type to be returned from the `send()` function. In almost all
    /// cases, this should be [crate::common::error::Error], where
    /// `common::error::Error` implements `From<>` for the error type returned
    /// by your networking library. This ensures a consistent
    /// experience for users of `lemon-bugsnag-rs`. See the `From<>`
    /// implementations in [Error](crate::common::error::Error#trait-implementations)
    /// for examples of this being done with the Ureq and Reqwest networking
    /// libraries.

    /// The error type returned by the backend client.
    ///
    /// ```
    /// // This example requires the async feature.
    /// // This example requires the reqwest feature.
    ///
    /// use lemon_bugsnag_rs::common::traits::client_trait_async::ClientTraitAsync;
    /// use reqwest::Response;
    ///
    /// struct MyClient {}
    /// # #[cfg(feature = "reqwest")]
    /// # {
    ///    
    /// # #[cfg(norun)]
    /// impl ClientTraitAsync for MyClient {
    /// #    type Response = Response;
    ///     type Error = lemon_bugsnag_rs::common::error::Error;
    ///
    ///     // ... implement send()
    /// }
    /// # }
    /// ```
    type Error: std::error::Error;

    /// Send the client's payload. Relies on the `async_trait` crate for both
    /// declaration and implementation. See
    ///     [the asynchronous Reqwest client](crate::error::reqwest::client::non_blocking::ReqwestErrorAsync)
    /// for an example implementation.
    ///
    /// # Example
    /// ```
    /// // This requires the error-client feature to be enabled
    /// // This requires the async feature to be enabled
    /// // This requires the reqwest feature to be enabled
    ///
    /// use lemon_bugsnag_rs::common::bundle::*;
    ///
    /// # #[cfg(feature = "async")]
    /// # tokio::runtime::Builder::new_current_thread()
    /// # .enable_all()
    /// # .build()
    /// # .expect("Failed to build current-thread runtime")
    /// # .block_on(async {
    /// let mut cb = ClientBuilder::error();
    ///
    /// # #[cfg(norun)]
    /// cb.configure(
    ///     std::env::var("NAB_BUGSNAG_RS_API_KEY").unwrap().as_str()
    ///     , "NAB BugSnag RS Doctest Error Class"
    ///     , "Some generic error message"
    ///     , "NAB BugSnag RS Doctest Notifier"
    ///     , "0.0.2"
    ///     , "Fake App Stage"
    ///     , "Fake Release Stage"
    /// );
    ///
    /// # cb.configure(
    /// #   "fake API key"
    /// #   , "NAB BugSnag RS Doctest Error Class"
    /// #   , "Some generic error message"
    /// #   , "NAB BugSnag RS Doctest Notifier"
    /// #   , "0.0.2"
    /// #   , "Fake App Stage"
    /// #   , "Fake Release Stage"
    /// # );
    ///
    /// # #[cfg(norun)]
    /// let result = cb.reqwest().non_blocking().build().unwrap().send().await;
    ///
    /// // Handle result
    /// // ...
    /// # });
    /// ```
    async fn send(&mut self) -> Result<Self::Response, Self::Error>;
}