1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// intern
use crate::error;


pub trait Trait<SourceType> {
    fn propagate(self, context: error::Context) -> error::Error<SourceType>;
}


/**
 * An error that is yet to be put in perspective with its context.
 *
 * Error instances are made from their Source and then propagated through one or multiple Context instances.
 */
pub struct Propagation<SourceType> {
    error_source: SourceType,
}


impl<SourceType> Propagation<SourceType> {
    pub fn new(error_source: SourceType) -> Self {
        Propagation {
            error_source,
        }
    }
}


impl<SourceType> Trait<SourceType> for Propagation<SourceType> {
    fn propagate(self, context: error::Context) -> error::Error<SourceType> {
        use error::Trait;

        let error = error::Error {
            stack_trace: error::StackTrace::new(),
            error_source: self.error_source,
        };
        return error.propagate(context);
    }
}