-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathsolution.rs
More file actions
43 lines (33 loc) · 1 KB
/
solution.rs
File metadata and controls
43 lines (33 loc) · 1 KB
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
extern crate alloc;
use alloc::collections::BTreeMap;
use rdf_model::HeapTerm;
use crate::variable::Variable;
pub struct Solution {
bindings: BTreeMap<Variable, HeapTerm>,
}
impl Solution {
pub fn new(bindings: BTreeMap<Variable, impl Into<HeapTerm>>) -> Self {
let bindings = bindings
.into_iter()
.map(|(var, term)| (var, term.into()))
.collect();
Self { bindings }
}
pub fn binding(&self, var: &Variable) -> Option<&HeapTerm> {
self.bindings.get(var)
}
pub fn each_binding(&self) -> impl Iterator<Item = (&Variable, &HeapTerm)> {
self.bindings.iter()
}
pub fn each_name(&self) -> impl Iterator<Item = &Variable> {
self.bindings.keys()
}
pub fn each_value(&self) -> impl Iterator<Item = &HeapTerm> {
self.bindings.values()
}
}
impl core::fmt::Debug for Solution {
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
f.debug_struct("Solution").finish()
}
}