rbe/
candidate.rs

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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
use std::{fmt::Display, ops::Deref};

use crate::{Component, Key, MatchCond, Ref, Value};

type CandidateItem<K, V, R> = (K, V, Component, MatchCond<K, V, R>);

// TODO: We are not using the struct yet
#[derive(Debug, Clone)]
pub struct Candidate<K, V, R>
where
    K: Key,
    V: Value,
    R: Ref,
{
    values: Vec<CandidateItem<K, V, R>>,
}

impl<K, V, R> Display for Candidate<K, V, R>
where
    K: Key + Display,
    V: Value + Display,
    R: Ref + Display,
{
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        f.write_str("Candidate")?;
        for (key, value, component, cond) in self.values.iter() {
            write!(f, "Candidate value: {key} {value} {component} {cond}")?;
        }
        Ok(())
    }
}

/*impl <K,V,R> IntoIterator for Candidate<K,V,R>
where
  K: Key + Display,
  V: Value + Display,
  R: Ref + Display, {
    type Item = (K, V, Component, MatchCond<K, V, R>);

    type IntoIter = ;

    fn into_iter(self) -> Self::IntoIter {
        todo!()
    }
}*/

impl<K, V, R> Deref for Candidate<K, V, R>
where
    K: Key + Display,
    V: Value + Display,
    R: Ref + Display,
{
    type Target = Vec<(K, V, Component, MatchCond<K, V, R>)>;

    fn deref(&self) -> &Self::Target {
        &self.values
    }
}

/*impl <K,V,R> Iterator for Candidate<K,V,R>
where
  K: Key + Display,
  V: Value + Display,
  R: Ref + Display, {
    type Item = (K, V, Component, MatchCond<K, V, R>);

    fn next(&mut self) -> Option<Self::Item> {
        self.values.iter().map(|v| v.clone())
    }
}*/