toasty_core/stmt/
value_list.rs1use crate::stmt::Value;
2
3impl Value {
4 pub fn list_from_vec(items: Vec<Self>) -> Self {
5 Self::List(items)
6 }
7
8 pub fn is_list(&self) -> bool {
9 matches!(self, Self::List(_))
10 }
11
12 #[track_caller]
13 pub fn unwrap_list(self) -> Vec<Value> {
14 match self {
15 Value::List(list) => list,
16 _ => panic!("expected Value::List; actual={self:#?}"),
17 }
18 }
19}
20
21impl From<Vec<Value>> for Value {
22 fn from(value: Vec<Value>) -> Self {
23 Value::List(value)
24 }
25}
26
27impl<T, const N: usize> PartialEq<[T; N]> for Value
28where
29 T: PartialEq<Value>,
30{
31 fn eq(&self, other: &[T; N]) -> bool {
32 match self {
33 Value::List(items) => items.iter().enumerate().all(|(i, item)| other[i].eq(item)),
34 _ => false,
35 }
36 }
37}
38
39impl<T, const N: usize> PartialEq<Value> for [T; N]
40where
41 T: PartialEq<Value>,
42{
43 fn eq(&self, other: &Value) -> bool {
44 other.eq(self)
45 }
46}