amadeus_types/
lib.rs

1//! Harmonious distributed data processing & analysis in Rust.
2//!
3//! <p style="font-family: 'Fira Sans',sans-serif;padding:0.3em 0"><strong>
4//! <a href="https://crates.io/crates/amadeus">📦&nbsp;&nbsp;Crates.io</a>&nbsp;&nbsp;│&nbsp;&nbsp;<a href="https://github.com/constellation-rs/amadeus">📑&nbsp;&nbsp;GitHub</a>&nbsp;&nbsp;│&nbsp;&nbsp;<a href="https://constellation.zulipchat.com/#narrow/stream/213231-amadeus">💬&nbsp;&nbsp;Chat</a>
5//! </strong></p>
6//!
7//! This is a support crate of [Amadeus](https://github.com/constellation-rs/amadeus) and is not intended to be used directly. These types are re-exposed in [`amadeus::data`](https://docs.rs/amadeus/0.3/amadeus/data/index.html).
8
9#![doc(html_root_url = "https://docs.rs/amadeus-types/0.4.3")]
10#![warn(
11	// missing_copy_implementations,
12	// missing_debug_implementations,
13	// missing_docs,
14	trivial_numeric_casts,
15	unused_import_braces,
16	unused_qualifications,
17	unused_results,
18	// unreachable_pub,
19	clippy::pedantic,
20)]
21#![allow(
22	clippy::module_name_repetitions,
23	clippy::similar_names,
24	clippy::if_not_else,
25	clippy::must_use_candidate,
26	clippy::missing_errors_doc,
27	clippy::doc_markdown,
28	clippy::wildcard_imports,
29	clippy::default_trait_access,
30	clippy::inline_always,
31	clippy::too_many_lines,
32	clippy::missing_panics_doc
33)]
34#![deny(unsafe_code)]
35
36#[macro_export]
37macro_rules! array {
38	($array_macro:ident) => (
39		$array_macro!(0 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); // 40 48 50 56 64 72 96 100 128 160 192 200 224 256 384 512 768 1024 2048 4096 8192 16384 32768 65536);
40	)
41}
42#[macro_export]
43macro_rules! tuple {
44	($tuple_macro:ident) => (
45		$tuple_macro!(0);
46		$tuple_macro!(1 A 0);
47		$tuple_macro!(2 A 0 B 1);
48		$tuple_macro!(3 A 0 B 1 C 2);
49		$tuple_macro!(4 A 0 B 1 C 2 D 3);
50		$tuple_macro!(5 A 0 B 1 C 2 D 3 E 4);
51		$tuple_macro!(6 A 0 B 1 C 2 D 3 E 4 F 5);
52		$tuple_macro!(7 A 0 B 1 C 2 D 3 E 4 F 5 G 6);
53		$tuple_macro!(8 A 0 B 1 C 2 D 3 E 4 F 5 G 6 H 7);
54		$tuple_macro!(9 A 0 B 1 C 2 D 3 E 4 F 5 G 6 H 7 I 8);
55		$tuple_macro!(10 A 0 B 1 C 2 D 3 E 4 F 5 G 6 H 7 I 8 J 9);
56		$tuple_macro!(11 A 0 B 1 C 2 D 3 E 4 F 5 G 6 H 7 I 8 J 9 K 10);
57		$tuple_macro!(12 A 0 B 1 C 2 D 3 E 4 F 5 G 6 H 7 I 8 J 9 K 10 L 11);
58		// $tuple_macro!(13 A 0 B 1 C 2 D 3 E 4 F 5 G 6 H 7 I 8 J 9 K 10 L 11 M 12);
59		// $tuple_macro!(14 A 0 B 1 C 2 D 3 E 4 F 5 G 6 H 7 I 8 J 9 K 10 L 11 M 12 N 13);
60		// $tuple_macro!(15 A 0 B 1 C 2 D 3 E 4 F 5 G 6 H 7 I 8 J 9 K 10 L 11 M 12 N 13 O 14);
61		// $tuple_macro!(16 A 0 B 1 C 2 D 3 E 4 F 5 G 6 H 7 I 8 J 9 K 10 L 11 M 12 N 13 O 14 P 15);
62		// $tuple_macro!(17 A 0 B 1 C 2 D 3 E 4 F 5 G 6 H 7 I 8 J 9 K 10 L 11 M 12 N 13 O 14 P 15 Q 16);
63		// $tuple_macro!(18 A 0 B 1 C 2 D 3 E 4 F 5 G 6 H 7 I 8 J 9 K 10 L 11 M 12 N 13 O 14 P 15 Q 16 R 17);
64		// $tuple_macro!(19 A 0 B 1 C 2 D 3 E 4 F 5 G 6 H 7 I 8 J 9 K 10 L 11 M 12 N 13 O 14 P 15 Q 16 R 17 S 18);
65		// $tuple_macro!(20 A 0 B 1 C 2 D 3 E 4 F 5 G 6 H 7 I 8 J 9 K 10 L 11 M 12 N 13 O 14 P 15 Q 16 R 17 S 18 T 19);
66		// $tuple_macro!(21 A 0 B 1 C 2 D 3 E 4 F 5 G 6 H 7 I 8 J 9 K 10 L 11 M 12 N 13 O 14 P 15 Q 16 R 17 S 18 T 19 U 20);
67		// $tuple_macro!(22 A 0 B 1 C 2 D 3 E 4 F 5 G 6 H 7 I 8 J 9 K 10 L 11 M 12 N 13 O 14 P 15 Q 16 R 17 S 18 T 19 U 20 V 21);
68		// $tuple_macro!(23 A 0 B 1 C 2 D 3 E 4 F 5 G 6 H 7 I 8 J 9 K 10 L 11 M 12 N 13 O 14 P 15 Q 16 R 17 S 18 T 19 U 20 V 21 W 22);
69		// $tuple_macro!(24 A 0 B 1 C 2 D 3 E 4 F 5 G 6 H 7 I 8 J 9 K 10 L 11 M 12 N 13 O 14 P 15 Q 16 R 17 S 18 T 19 U 20 V 21 W 22 X 23);
70		// $tuple_macro!(25 A 0 B 1 C 2 D 3 E 4 F 5 G 6 H 7 I 8 J 9 K 10 L 11 M 12 N 13 O 14 P 15 Q 16 R 17 S 18 T 19 U 20 V 21 W 22 X 23 Y 24);
71		// $tuple_macro!(26 A 0 B 1 C 2 D 3 E 4 F 5 G 6 H 7 I 8 J 9 K 10 L 11 M 12 N 13 O 14 P 15 Q 16 R 17 S 18 T 19 U 20 V 21 W 22 X 23 Y 24 Z 25);
72		// $tuple_macro!(27 A 0 B 1 C 2 D 3 E 4 F 5 G 6 H 7 I 8 J 9 K 10 L 11 M 12 N 13 O 14 P 15 Q 16 R 17 S 18 T 19 U 20 V 21 W 22 X 23 Y 24 Z 25 AA 26);
73		// $tuple_macro!(28 A 0 B 1 C 2 D 3 E 4 F 5 G 6 H 7 I 8 J 9 K 10 L 11 M 12 N 13 O 14 P 15 Q 16 R 17 S 18 T 19 U 20 V 21 W 22 X 23 Y 24 Z 25 AA 26 AB 27);
74		// $tuple_macro!(29 A 0 B 1 C 2 D 3 E 4 F 5 G 6 H 7 I 8 J 9 K 10 L 11 M 12 N 13 O 14 P 15 Q 16 R 17 S 18 T 19 U 20 V 21 W 22 X 23 Y 24 Z 25 AA 26 AB 27 AC 28);
75		// $tuple_macro!(30 A 0 B 1 C 2 D 3 E 4 F 5 G 6 H 7 I 8 J 9 K 10 L 11 M 12 N 13 O 14 P 15 Q 16 R 17 S 18 T 19 U 20 V 21 W 22 X 23 Y 24 Z 25 AA 26 AB 27 AC 28 AD 29);
76		// $tuple_macro!(31 A 0 B 1 C 2 D 3 E 4 F 5 G 6 H 7 I 8 J 9 K 10 L 11 M 12 N 13 O 14 P 15 Q 16 R 17 S 18 T 19 U 20 V 21 W 22 X 23 Y 24 Z 25 AA 26 AB 27 AC 28 AD 29 AE 30);
77		// $tuple_macro!(32 A 0 B 1 C 2 D 3 E 4 F 5 G 6 H 7 I 8 J 9 K 10 L 11 M 12 N 13 O 14 P 15 Q 16 R 17 S 18 T 19 U 20 V 21 W 22 X 23 Y 24 Z 25 AA 26 AB 27 AC 28 AD 29 AE 30 AF 31);
78	)
79}
80
81mod array;
82mod data;
83mod decimal;
84mod group;
85mod http;
86mod list;
87mod ord;
88mod time;
89mod util;
90mod value;
91mod value_required;
92
93use std::{
94	error::Error, fmt::{self, Debug, Display}
95};
96
97pub use self::{
98	array::{Bson, Enum, Json}, data::Data, decimal::Decimal, group::Group, http::{IpAddr, ParseAddrError, ParseUrlError, ParseWebpageError, Url, Webpage}, list::{List, ListVec}, ord::AmadeusOrd, time::{
99		Date, DateTime, DateTimeWithoutTimezone, DateWithoutTimezone, ParseDateError, Time, TimeWithoutTimezone, Timezone
100	}, value::{Schema, SchemaIncomplete, Value}, value_required::ValueRequired
101};
102
103pub mod __internal {
104	pub use serde::{
105		de::{Deserializer, Error, SeqAccess, Visitor}, ser::{SerializeTuple, Serializer}, Deserialize, Serialize
106	};
107}
108
109/// This trait lets one downcast a generic type like [`Value`] to a specific type like
110/// `u64`.
111///
112/// It exists, rather than for example using [`TryInto`](std::convert::TryInto), due to
113/// coherence issues with downcasting to foreign types like `Option<T>`.
114pub trait DowncastFrom<T>
115where
116	T: Downcast<Self>,
117	Self: Sized,
118{
119	fn downcast_from(t: T) -> Result<Self, DowncastError>
120	where
121		Self: Sized;
122}
123pub trait Downcast<T> {
124	fn downcast(self) -> Result<T, DowncastError>;
125}
126impl<A, B> Downcast<A> for B
127where
128	A: DowncastFrom<B>,
129{
130	fn downcast(self) -> Result<A, DowncastError> {
131		A::downcast_from(self)
132	}
133}
134
135impl<A, B> DowncastFrom<A> for Box<B>
136where
137	B: DowncastFrom<A>,
138{
139	fn downcast_from(t: A) -> Result<Self, DowncastError>
140	where
141		Self: Sized,
142	{
143		t.downcast().map(Box::new)
144	}
145}
146
147#[derive(Copy, Clone, PartialEq, Eq, Debug)]
148pub struct DowncastError {
149	pub from: &'static str,
150	pub to: &'static str,
151}
152impl Error for DowncastError {
153	fn description(&self) -> &str {
154		"invalid downcast"
155	}
156}
157impl Display for DowncastError {
158	fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
159		write!(f, "could not downcast \"{}\" to \"{}\"", self.from, self.to)
160	}
161}