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
use std::fmt::Display;
/// Represents a evaluated expression of type `S`.
#[derive(Clone, Copy)]
pub struct Eval<L: Display + Copy, S> {
/// A human-readable label that describes the expression that was evaluated
/// (e.g. `"x"` or `"f(x, y)"`).
pub label: L,
/// The value of the evaluated expression.
pub value: S,
}
impl<L: Display + Copy, S> Eval<L, S> {
/// Returns an [`Eval`] with the same label and a reference to the original value.
pub fn as_ref(&self) -> Eval<L, &S> {
Eval {
label: self.label,
value: &self.value,
}
}
}
impl<L: Display + Copy, S> Eval<L, &S> {
/// Returns an [`Eval`] with the same label and a clone of the original value.
pub fn cloned(self) -> Eval<L, S>
where
S: Clone,
{
Eval {
label: self.label,
value: self.value.clone(),
}
}
/// Returns an [`Eval`] with the same label and a copy of the original value.
pub fn copied(self) -> Eval<L, S>
where
S: Copy,
{
Eval {
label: self.label,
value: *self.value,
}
}
}