lemon_bugsnag_rs 0.1.2

A library for interacting with the BugSnag error-reporting and sessions APIs.
Documentation
use std::fmt;

use serde::Serialize;

/// Enum corresponding to the `events -> severity` key in the BugSnag
/// error-reporting API payload. Represents the severity of the error
///
/// ```
/// use lemon_bugsnag_rs::error::payload::events::enums::Severity;
///
/// let severity_variant = Severity::Error;
///
/// match severity_variant {
///     Severity::Info => () /* Not this one */,
///     Severity::Warning => () /* Not this one */,
///     Severity::Error => {
///         // Ah, here we go
///         // Do stuff...
///     },
///     _ => () // Catch-all for remaining variants (others may be added later)
/// }
/// ```
#[derive(Clone, Debug, Eq, PartialEq)]
pub enum Severity {
    /// Represents the Info Severity
    Info,
    /// Represents the Warning Severity
    Warning,
    /// Represents the Error Severity
    Error,
}

impl fmt::Display for Severity {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        let output = format!("{:?}", self).to_lowercase();

        write!(f, "{}", output)
    }
}

impl Serialize for Severity {
    fn serialize<S>(
        &self,
        serializer: S,
    ) -> std::prelude::v1::Result<S::Ok, S::Error>
    where
        S: serde::Serializer,
    {
        let output = format!("{:?}", self).to_lowercase();

        serializer.serialize_str(&output)
    }
}