#[cfg(feature = "json")]
use serde_json::Value;
use crate::{Message, MessageFactory};
use std::borrow::Cow;
use std::error::Error;
pub trait Loggable {
fn to_message(self) -> Message;
}
impl Loggable for Message {
fn to_message(self) -> Message {
self
}
}
impl<S: Into<Cow<'static, str>>> Loggable for (S, &'static str) {
fn to_message(self) -> Message {
MessageFactory::string_msg(self.0, self.1)
}
}
impl<S: Into<Cow<'static, str>>> Loggable for (S, String) {
fn to_message(self) -> Message {
MessageFactory::string_msg(self.0, self.1)
}
}
impl<S: Into<Cow<'static, str>>> Loggable for (S, Cow<'static, str>) {
fn to_message(self) -> Message {
MessageFactory::string_msg(self.0, self.1)
}
}
impl<S: Into<Cow<'static, str>>> Loggable for (S, &String) {
fn to_message(self) -> Message {
MessageFactory::string_msg(self.0, self.1.clone())
}
}
#[cfg(feature = "json")]
#[cfg_attr(docsrs, doc(cfg(feature = "json")))]
impl<S: Into<Cow<'static, str>>> Loggable for (S, Value) {
fn to_message(self) -> Message {
MessageFactory::json_msg(self.0, self.1)
}
}
impl<S: Into<Cow<'static, str>>> Loggable for (S, Box<dyn Error + Send + Sync>) {
fn to_message(self) -> Message {
MessageFactory::error_msg(self.0, self.1)
}
}