rbe/
candidate.rs

1use std::{fmt::Display, ops::Deref};
2
3use crate::{Component, Key, MatchCond, Ref, Value};
4
5type CandidateItem<K, V, R> = (K, V, Component, MatchCond<K, V, R>);
6
7// TODO: We are not using the struct yet
8#[derive(Debug, Clone)]
9pub struct Candidate<K, V, R>
10where
11    K: Key,
12    V: Value,
13    R: Ref,
14{
15    values: Vec<CandidateItem<K, V, R>>,
16}
17
18impl<K, V, R> Display for Candidate<K, V, R>
19where
20    K: Key + Display,
21    V: Value + Display,
22    R: Ref + Display,
23{
24    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
25        f.write_str("Candidate")?;
26        for (key, value, component, cond) in self.values.iter() {
27            write!(f, "Candidate value: {key} {value} {component} {cond}")?;
28        }
29        Ok(())
30    }
31}
32
33/*impl <K,V,R> IntoIterator for Candidate<K,V,R>
34where
35  K: Key + Display,
36  V: Value + Display,
37  R: Ref + Display, {
38    type Item = (K, V, Component, MatchCond<K, V, R>);
39
40    type IntoIter = ;
41
42    fn into_iter(self) -> Self::IntoIter {
43        todo!()
44    }
45}*/
46
47impl<K, V, R> Deref for Candidate<K, V, R>
48where
49    K: Key + Display,
50    V: Value + Display,
51    R: Ref + Display,
52{
53    type Target = Vec<(K, V, Component, MatchCond<K, V, R>)>;
54
55    fn deref(&self) -> &Self::Target {
56        &self.values
57    }
58}
59
60/*impl <K,V,R> Iterator for Candidate<K,V,R>
61where
62  K: Key + Display,
63  V: Value + Display,
64  R: Ref + Display, {
65    type Item = (K, V, Component, MatchCond<K, V, R>);
66
67    fn next(&mut self) -> Option<Self::Item> {
68        self.values.iter().map(|v| v.clone())
69    }
70}*/