Documentation
use super::{
    super::super::{common::*, problem::*},
    problem::*,
};

use std::error::*;

//
// IntoSerdeProblem
//

/// Convert into a [SerdeProblem].
#[cfg_attr(docsrs, doc(cfg(feature = "serde")))]
pub trait IntoSerdeProblem {
    /// Convert into a [SerdeProblem] via [SerializationError].
    ///
    /// You probably want to call
    /// [from_serde_problem](super::result::FromSerdeProblemResult::from_serde_problem)
    /// to eventually map it back and avoid re-wrapping it and thus losing the causation chain.
    fn into_serde_serialize_problem(self) -> SerdeProblem;

    /// Convert into a [SerdeProblem] via [DeserializationError].
    ///
    /// You probably want to call
    /// [from_serde_problem](super::result::FromSerdeProblemResult::from_serde_problem)
    /// to eventually map it back and avoid re-wrapping it and thus losing the causation chain.
    fn into_serde_deserialize_problem(self) -> SerdeProblem;
}

impl<ErrorT> IntoSerdeProblem for ErrorT
where
    ErrorT: 'static + Error + Send + Sync,
{
    #[track_caller]
    fn into_serde_serialize_problem(self) -> SerdeProblem {
        self.into_problem()
            .via(SerializationError::new("serde"))
            .into()
    }

    #[track_caller]
    fn into_serde_deserialize_problem(self) -> SerdeProblem {
        self.into_problem()
            .via(DeserializationError::new("serde"))
            .into()
    }
}