1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
use ;
use ;
use crate;
/// Build [marrow arrays][marrow::array::Array] from the given items
///
/// `items` should be given in the form of a list of records (e.g., a vector of
/// structs). To serialize single values, use the [`Items`][crate::utils::Items]
/// wrapper.
///
/// To build arrays record by record use [`ArrayBuilder`].
///
/// Example:
///
/// ```rust
/// # fn main() -> serde_arrow::Result<()> {
/// use marrow::{array::{Array, PrimitiveArray}, datatypes::Field};
/// use serde::{Serialize, Deserialize};
/// use serde_arrow::schema::{SchemaLike, TracingOptions};
///
/// ##[derive(Debug, PartialEq, Serialize, Deserialize)]
/// struct Record {
/// a: Option<f32>,
/// b: u64,
/// }
///
/// let items = vec![
/// Record { a: Some(1.0), b: 2},
/// // ...
/// ];
///
/// let fields = Vec::<Field>::from_type::<Record>(TracingOptions::default())?;
/// let arrays = serde_arrow::to_marrow(&fields, &items)?;
///
/// assert_eq!(
/// arrays,
/// vec![
/// Array::Float32(PrimitiveArray {
/// validity: Some(marrow::bit_vec![true]),
/// values: vec![1.0],
/// }),
/// Array::UInt64(PrimitiveArray {
/// validity: None,
/// values: vec![2],
/// }),
/// ],
/// );
/// # Ok(())
/// # }
/// ```
///
/// Deserialize items from [marrow views][marrow::view::View]
///
/// The type should be a list of records (e.g., a vector of structs). To
/// deserialize single values, use the [`Items`][crate::utils::Items] wrapper.
///
/// ```rust
/// # fn main() -> serde_arrow::Result<()> {
/// use marrow::{datatypes::Field, view::{BitsWithOffset, View, PrimitiveView}};
/// use serde::{Deserialize, Serialize};
/// use serde_arrow::schema::{SchemaLike, TracingOptions};
///
/// ##[derive(Debug, PartialEq, Deserialize, Serialize)]
/// struct Record {
/// a: Option<f32>,
/// b: u64,
/// }
///
/// let views = vec![
/// View::Float32(PrimitiveView {
/// validity: Some(BitsWithOffset {
/// offset: 0,
/// data: &const { marrow::bit_array![true, false, true] },
/// }),
/// values: &[13.0, 0.0, 17.0],
/// }),
/// View::UInt64(PrimitiveView {
/// validity: None,
/// values: &[21, 42, 84],
/// }),
/// ];
///
/// let fields = Vec::<Field>::from_type::<Record>(TracingOptions::default())?;
/// let items: Vec<Record> = serde_arrow::from_marrow(&fields, &views)?;
///
/// assert_eq!(
/// items,
/// vec![
/// Record { a: Some(13.0), b: 21 },
/// Record { a: None, b: 42 },
/// Record { a: Some(17.0), b: 84 },
/// ],
/// );
/// # Ok(())
/// # }
/// ```
///