Debian Codegraph @

src/minusplus.rs

raw symbols SCIP
1 use std::ops::{Index, IndexMut};
2
3 /// Represent data related to removed/minus and added/plus lines which
4 /// can be indexed with [`MinusPlusIndex::{Plus`](MinusPlusIndex::Plus)`,`[`Minus}`](MinusPlusIndex::Minus).
5 #[derive(Debug, Clone, PartialEq, Eq)]
6 pub struct MinusPlus<T> {
7 pub minus: T,
8 pub plus: T,
9 }
10
11 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
12 pub enum MinusPlusIndex {
13 Minus,
14 Plus,
15 }
16
17 pub use MinusPlusIndex::*;
18
19 impl<T> Index<MinusPlusIndex> for MinusPlus<T> {
20 type Output = T;
21 fn index(&self, side: MinusPlusIndex) -> &Self::Output {
22 match side {
23 Minus => &self.minus,
24 Plus => &self.plus,
25 }
26 }
27 }
28
29 impl<T> IndexMut<MinusPlusIndex> for MinusPlus<T> {
30 fn index_mut(&mut self, side: MinusPlusIndex) -> &mut Self::Output {
31 match side {
32 Minus => &mut self.minus,
33 Plus => &mut self.plus,
34 }
35 }
36 }
37
38 impl<T> MinusPlus<T> {
39 pub fn new(minus: T, plus: T) -> Self {
40 MinusPlus { minus, plus }
41 }
42 }
43
44 impl<T: Default> Default for MinusPlus<T> {
45 fn default() -> Self {
46 Self {
47 minus: T::default(),
48 plus: T::default(),
49 }
50 }
51 }