pub use crate::core::{display::strong, information::Information, should::Should};
pub use std::fmt::Debug;
#[derive(Debug)]
pub struct ShouldImpl<L>
where
L: Debug,
{
pub left: Option<L>,
pub(crate) truthness: bool,
pub(crate) info: Information,
}
impl<L> ShouldImpl<L>
where
L: Debug,
{
pub fn map_left<T: Debug, F>(self, f: F) -> ShouldImpl<T>
where
F: FnOnce(L) -> Option<T>,
{
let ShouldImpl {
left,
truthness,
info,
} = self;
let left = left.and_then(f);
ShouldImpl {
left,
truthness,
info,
}
}
pub fn truthness(&self) -> bool {
self.truthness
}
pub fn left_dbg(&self) -> &str {
&self.info.left_dbg
}
pub fn stringified(&self) -> Option<String> {
self.info
.from_macro
.as_ref()
.map(|x| strong(x.stringified).to_string())
}
pub fn add_message(&mut self, message: String) {
self.info.messages.push(message);
}
}
impl<L> Default for ShouldImpl<L>
where
L: Debug,
{
fn default() -> Self {
ShouldImpl {
left: None,
truthness: true,
info: Information::default(),
}
}
}
impl<L> From<ShouldImpl<L>> for Should<L>
where
L: Debug,
{
fn from(implem: ShouldImpl<L>) -> Self {
Should(implem)
}
}
impl<L> From<Should<L>> for ShouldImpl<L>
where
L: Debug,
{
fn from(should: Should<L>) -> Self {
should.0
}
}
impl<'a, L> From<&'a mut Should<L>> for &'a mut ShouldImpl<L>
where
L: Debug,
{
fn from(should: &'a mut Should<L>) -> Self {
&mut should.0
}
}