Skip to main content

cdrs_temp/types/
list.rs

1use crate::error::{Error, Result};
2use crate::frame::frame_result::{ColType, ColTypeOption, ColTypeOptionValue};
3use crate::types::blob::Blob;
4use crate::types::data_serialization_types::*;
5use crate::types::decimal::Decimal;
6use crate::types::map::Map;
7use crate::types::tuple::Tuple;
8use crate::types::udt::UDT;
9use crate::types::{AsRust, AsRustType, CBytes};
10use std::net::IpAddr;
11use uuid::Uuid;
12
13// TODO: consider using pointers to ColTypeOption and Vec<CBytes> instead of owning them.
14#[derive(Debug)]
15pub struct List {
16    /// column spec of the list, i.e. id should be List as it's a list and value should contain
17    /// a type of list items.
18    metadata: ColTypeOption,
19    data: Vec<CBytes>,
20}
21
22impl List {
23    pub fn new(data: Vec<CBytes>, metadata: ColTypeOption) -> List {
24        List {
25            metadata: metadata,
26            data: data,
27        }
28    }
29
30    fn map<T, F>(&self, f: F) -> Vec<T>
31    where
32        F: FnMut(&CBytes) -> T,
33    {
34        self.data.iter().map(f).collect()
35    }
36}
37
38impl AsRust for List {}
39
40list_as_rust!(Blob);
41list_as_rust!(String);
42list_as_rust!(bool);
43list_as_rust!(i64);
44list_as_rust!(i32);
45list_as_rust!(i16);
46list_as_rust!(i8);
47list_as_rust!(f64);
48list_as_rust!(f32);
49list_as_rust!(IpAddr);
50list_as_rust!(Uuid);
51list_as_rust!(List);
52list_as_rust!(Map);
53list_as_rust!(UDT);
54list_as_rust!(Tuple);
55list_as_rust!(Decimal);