toasty_core/stmt/
value_list.rs1use crate::stmt::Value;
4
5impl Value {
6 pub fn list_from_vec(items: Vec<Self>) -> Self {
16 Self::List(items)
17 }
18
19 pub fn is_list(&self) -> bool {
21 matches!(self, Self::List(_))
22 }
23
24 pub fn is_list_empty(&self) -> bool {
26 matches!(self, Self::List(items) if items.is_empty())
27 }
28
29 #[track_caller]
36 pub fn into_list_unwrap(self) -> Vec<Value> {
37 match self {
38 Value::List(list) => list,
39 _ => panic!("expected Value::List; actual={self:#?}"),
40 }
41 }
42}
43
44impl From<Vec<Value>> for Value {
45 fn from(value: Vec<Value>) -> Self {
46 Value::List(value)
47 }
48}
49
50impl<T, const N: usize> PartialEq<[T; N]> for Value
51where
52 T: PartialEq<Value>,
53{
54 fn eq(&self, other: &[T; N]) -> bool {
55 match self {
56 Value::List(items) => items.iter().enumerate().all(|(i, item)| other[i].eq(item)),
57 _ => false,
58 }
59 }
60}
61
62impl<T, const N: usize> PartialEq<Value> for [T; N]
63where
64 T: PartialEq<Value>,
65{
66 fn eq(&self, other: &Value) -> bool {
67 other.eq(self)
68 }
69}