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
#![forbid(unsafe_code)]
#![deny(
anonymous_parameters,
rust_2018_idioms,
trivial_casts,
trivial_numeric_casts,
unreachable_pub,
const_err,
illegal_floating_point_literal_pattern,
late_bound_lifetime_arguments,
path_statements,
patterns_in_fns_without_body,
clippy::all
)]
#![warn(
unused_extern_crates,
missing_copy_implementations,
missing_debug_implementations,
single_use_lifetimes,
unused_qualifications,
variant_size_differences,
clippy::pedantic,
clippy::nursery,
clippy::decimal_literal_representation,
clippy::get_unwrap,
clippy::option_unwrap_used,
clippy::print_stdout,
clippy::result_unwrap_used
)]
#![allow(
clippy::inline_always,
clippy::cast_possible_wrap,
clippy::cast_lossless,
clippy::module_name_repetitions,
clippy::must_use_candidate,
clippy::use_self,
)]
#[allow(unused_extern_crates)]
extern crate proc_macro;
macro_rules! error {
($message:literal) => {
error!(::proc_macro2::Span::call_site(), $message)
};
($span:expr, $message:literal) => {
Err(::syn::Error::new($span, $message))
};
($span:expr, $($args:expr),+) => {
Err(::syn::Error::new($span, format!($($args),+)))
};
}
mod kw {
use syn::custom_keyword;
custom_keyword!(am);
custom_keyword!(pm);
custom_keyword!(AM);
custom_keyword!(PM);
custom_keyword!(utc);
custom_keyword!(UTC);
}
mod date;
mod ext;
mod offset;
mod time;
mod time_crate;
use date::Date;
use offset::Offset;
use proc_macro_hack::proc_macro_hack;
use quote::ToTokens;
use syn::parse_macro_input;
use time::Time;
macro_rules! impl_macros {
($($name:ident : $type:ty),* $(,)?) => {
$(
#[proc_macro_hack]
pub fn $name(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
parse_macro_input!(input as $type).to_token_stream().into()
}
)*
};
}
impl_macros! {
time: Time,
offset: Offset,
date: Date,
}