derail-report 0.1.0

Tools for reporting `derail::Error`s.
Documentation
//! Integration tests.

// Remove when <https://github.com/rust-lang/rust-clippy/issues/11024> is fixed.
#![expect(clippy::tests_outside_test_module)]

use std::fmt;

use derail::Error;
use derail_macros::Error;

mod multiline;
mod oneline;

#[derive(Debug, Clone, Error)]
#[derail(
    type Details = D,
    display("{_0}"),
    impl Error where { D: fmt::Debug + Clone },
)]
pub(crate) struct Leaf<D>(
    pub(crate) &'static str,
    #[derail(details)] pub(crate) D,
);

#[derive(Debug, Clone, Error)]
#[derail(
    type Details = D,
    display("{_0}"),
    impl Error where {
        E: Error<Details = D>,
        D: fmt::Debug + Clone,
    },
)]
pub(crate) struct Tree<E, D>(
    pub(crate) &'static str,
    #[derail(details)] pub(crate) D,
    #[derail(children)] pub(crate) Vec<E>,
);

fn make_convoluted() -> Vec<impl Error<Details = ()>> {
    let leaf_one = Leaf("leaf 1", ());
    let leaf_two = Leaf("leaf 2", ());
    let leaf_three = Leaf("leaf 3", ());
    let leaves = vec![leaf_one, leaf_two, leaf_three];

    let layer_one_one = Tree("layer 1 1", (), leaves.clone());
    let layer_one_two = Tree("layer 1 2", (), leaves.clone());
    let layer_one_three = Tree("layer 1 3", (), leaves.clone());
    let layer_one = vec![layer_one_one, layer_one_two, layer_one_three];

    let layer_two_one = Tree("layer 2 1", (), layer_one.clone());
    let layer_two_two = Tree("layer 2 2", (), layer_one.clone());
    let layer_two_three = Tree("layer 2 3", (), layer_one.clone());

    vec![layer_two_one, layer_two_two, layer_two_three]
}

fn make_simpler() -> Vec<impl Error<Details = ()>> {
    let leaf_one = Leaf("leaf 1", ());
    let leaf_two = Leaf("leaf 2", ());
    let leaf_three = Leaf("leaf 3", ());
    let leaves = vec![leaf_one, leaf_two, leaf_three];

    let tree_one = Tree("tree 1", (), leaves.clone());
    let tree_two = Tree("tree 2", (), leaves);

    vec![tree_one, tree_two]
}