amadeus_types/
array.rs

1//! Implement [`Record`] for `Vec<u8>` (byte_array/fixed_len_byte_array), [`Bson`] (bson),
2//! `String` (utf8), [`Json`] (json), [`Enum`] (enum), and `[u8; N]`
3//! (fixed_len_byte_array).
4
5use serde::{Deserialize, Serialize};
6use std::{
7	cmp::Ordering, fmt::{self, Display}
8};
9
10use super::AmadeusOrd;
11
12/// A Rust type corresponding to the [Bson logical type](https://github.com/apache/parquet-format/blob/master/LogicalTypes.md#bson).
13#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize, Debug)]
14pub struct Bson(Vec<u8>);
15impl Bson {
16	pub fn capacity(&self) -> usize {
17		self.0.capacity()
18	}
19}
20impl AmadeusOrd for Bson {
21	fn amadeus_cmp(&self, other: &Self) -> Ordering {
22		Ord::cmp(self, other)
23	}
24}
25impl From<Bson> for Vec<u8> {
26	fn from(json: Bson) -> Self {
27		json.0
28	}
29}
30impl From<Vec<u8>> for Bson {
31	fn from(string: Vec<u8>) -> Self {
32		Self(string)
33	}
34}
35
36// `String` corresponds to the [UTF8/String logical type](https://github.com/apache/parquet-format/blob/master/LogicalTypes.md#string)
37
38/// A Rust type corresponding to the [Json logical type](https://github.com/apache/parquet-format/blob/master/LogicalTypes.md#json).
39#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize, Debug)]
40pub struct Json(String);
41impl Json {
42	pub fn capacity(&self) -> usize {
43		self.0.capacity()
44	}
45}
46impl AmadeusOrd for Json {
47	fn amadeus_cmp(&self, other: &Self) -> Ordering {
48		Ord::cmp(self, other)
49	}
50}
51impl Display for Json {
52	fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
53		self.0.fmt(f)
54	}
55}
56impl From<Json> for String {
57	fn from(json: Json) -> Self {
58		json.0
59	}
60}
61impl From<String> for Json {
62	fn from(string: String) -> Self {
63		Self(string)
64	}
65}
66
67/// A Rust type corresponding to the [Enum logical type](https://github.com/apache/parquet-format/blob/master/LogicalTypes.md#enum).
68#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize, Debug)]
69pub struct Enum(String);
70impl Enum {
71	pub fn capacity(&self) -> usize {
72		self.0.capacity()
73	}
74}
75impl AmadeusOrd for Enum {
76	fn amadeus_cmp(&self, other: &Self) -> Ordering {
77		Ord::cmp(self, other)
78	}
79}
80impl Display for Enum {
81	fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
82		self.0.fmt(f)
83	}
84}
85impl From<Enum> for String {
86	fn from(enum_: Enum) -> Self {
87		enum_.0
88	}
89}
90impl From<String> for Enum {
91	fn from(string: String) -> Self {
92		Self(string)
93	}
94}