specta/datatype/list.rs
1use super::DataType;
2
3/// Sequential collection type, such as [`Vec`](std::vec::Vec), arrays, slices,
4/// or set-like collections.
5#[derive(Debug, Clone, PartialEq, Eq, Hash)]
6#[non_exhaustive]
7pub struct List {
8 /// Type of each element in the list.
9 pub ty: Box<DataType>,
10 /// Fixed number of elements when known.
11 ///
12 /// `None` represents a variable-length collection.
13 pub length: Option<usize>,
14 /// Whether elements are expected to be unique, as with set-like types.
15 pub unique: bool,
16}
17
18impl List {
19 /// Create a new list of a given type.
20 pub fn new(ty: DataType) -> Self {
21 Self {
22 ty: Box::new(ty),
23 length: None,
24 unique: false,
25 }
26 }
27}
28
29impl From<List> for DataType {
30 fn from(t: List) -> Self {
31 Self::List(t)
32 }
33}