midenc_hir/
direction.rs

1/// A marker trait for abstracting over the direction in which a traversal is performed, or
2/// information is propagated by an analysis, i.e. forward or backward.
3///
4/// This trait is sealed as there are only two possible directions.
5#[allow(private_bounds)]
6pub trait Direction: sealed::Direction {
7    fn is_forward() -> bool {
8        Self::IS_FORWARD
9    }
10    fn is_backward() -> bool {
11        !Self::IS_FORWARD
12    }
13}
14
15impl<D: sealed::Direction> Direction for D {}
16
17mod sealed {
18    pub trait Direction: Default {
19        const IS_FORWARD: bool;
20    }
21
22    #[derive(Debug, Copy, Clone, Default)]
23    pub struct Forward;
24    impl Direction for Forward {
25        const IS_FORWARD: bool = true;
26    }
27
28    #[derive(Debug, Copy, Clone, Default)]
29    pub struct Backward;
30    impl Direction for Backward {
31        const IS_FORWARD: bool = false;
32    }
33}
34
35pub use self::sealed::{Backward, Forward};