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
use super::Expression;
use crate::Tuple;
#[derive(Clone, Debug)]
pub struct Singleton<T>(T)
where
T: Tuple;
impl<T: Tuple> Singleton<T> {
pub fn new(tuple: T) -> Self {
Self(tuple)
}
#[inline(always)]
pub fn tuple(&self) -> &T {
&self.0
}
#[inline(always)]
pub fn into_tuple(self) -> T {
self.0
}
}
impl<T> Expression<T> for Singleton<T>
where
T: Tuple,
{
fn visit<V>(&self, visitor: &mut V)
where
V: super::Visitor,
{
visitor.visit_singleton(&self)
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_new() {
assert_eq!(42, Singleton::new(42).into_tuple());
}
#[test]
fn test_clone() {
let s = Singleton::new(42);
assert_eq!(42, s.clone().into_tuple());
}
}