whisky_common/data/primitives/
list.rs1use serde_json::{json, Value};
2
3use crate::data::PlutusDataJson;
4
5#[derive(Clone, Debug)]
6pub struct List<T>
7where
8 T: Clone + PlutusDataJson,
9{
10 pub items: Vec<T>,
11}
12
13impl<T> List<T>
14where
15 T: Clone + PlutusDataJson,
16{
17 pub fn new(items: &[T]) -> Self {
18 List {
19 items: items.to_vec(),
20 }
21 }
22}
23
24impl<T> PlutusDataJson for List<T>
25where
26 T: Clone + PlutusDataJson,
27{
28 fn to_json(&self) -> Value {
29 let items_json = self
30 .items
31 .iter()
32 .map(|item| item.to_json())
33 .collect::<Vec<Value>>();
34 list(items_json)
35 }
36}
37
38pub fn list<T: Into<Value>>(p_list: Vec<T>) -> Value {
39 let list: Vec<Value> = p_list.into_iter().map(|item| item.into()).collect();
40 json!({ "list": list })
41}