1#![cfg_attr(docsrs, feature(doc_cfg))]
2#![doc = include_str!("../README.md")]
3#![allow(renamed_and_removed_lints)] #![allow(unknown_lints)] #![warn(missing_docs)]
7#![warn(noop_method_call)]
8#![warn(unreachable_pub)]
9#![warn(clippy::all)]
10#![deny(clippy::await_holding_lock)]
11#![deny(clippy::cargo_common_metadata)]
12#![deny(clippy::cast_lossless)]
13#![deny(clippy::checked_conversions)]
14#![allow(clippy::cognitive_complexity)] #![deny(clippy::debug_assert_with_mut_call)]
16#![deny(clippy::exhaustive_enums)]
17#![deny(clippy::exhaustive_structs)]
18#![deny(clippy::expl_impl_clone_on_copy)]
19#![deny(clippy::fallible_impl_from)]
20#![deny(clippy::implicit_clone)]
21#![deny(clippy::large_stack_arrays)]
22#![warn(clippy::manual_ok_or)]
23#![deny(clippy::missing_docs_in_private_items)]
24#![warn(clippy::needless_borrow)]
25#![warn(clippy::needless_pass_by_value)]
26#![warn(clippy::option_option)]
27#![warn(clippy::or_fun_call)]
28#![deny(clippy::print_stderr)]
29#![deny(clippy::print_stdout)]
30#![warn(clippy::rc_buffer)]
31#![deny(clippy::ref_option_ref)]
32#![warn(clippy::semicolon_if_nothing_returned)]
33#![warn(clippy::trait_duplication_in_bounds)]
34#![deny(clippy::unchecked_time_subtraction)]
35#![deny(clippy::unnecessary_wraps)]
36#![warn(clippy::unseparated_literal_suffix)]
37#![deny(clippy::unwrap_used)]
38#![deny(clippy::mod_module_files)]
39#![allow(clippy::let_unit_value)] #![allow(clippy::uninlined_format_args)]
41#![allow(clippy::significant_drop_in_scrutinee)] #![allow(clippy::result_large_err)] #![allow(clippy::needless_raw_string_hashes)] #![allow(clippy::needless_lifetimes)] #![allow(mismatched_lifetime_syntaxes)] #![allow(clippy::collapsible_if)] #![deny(clippy::unused_async)]
48#![deny(clippy::string_slice)] #![allow(recursion_depth_exceeding_limit)] #![warn(unnameable_types)]
54
55#[macro_export]
91macro_rules! caret_int {
92 {
93 $(#[$meta:meta])*
94 $v:vis struct $name:ident ( $numtype:ty ) {
95 $(
96 $(#[$item_meta:meta])*
97 $id:ident = $num:literal
98 ),*
99 $(,)?
100 }
101 } => {
102 #[derive(PartialEq,Eq,Copy,Clone)]
103 $(#[$meta])*
104 $v struct $name($numtype);
105
106 impl From<$name> for $numtype {
107 fn from(val: $name) -> $numtype { val.0 }
108 }
109 impl From<$numtype> for $name {
110 fn from(num: $numtype) -> $name { $name(num) }
111 }
112 impl $name {
113 $(
114 $( #[$item_meta] )*
115 pub const $id: $name = $name($num) ; )*
116 fn to_str(self) -> Option<&'static str> {
117 match self {
118 $( $name::$id => Some(stringify!($id)), )*
119 _ => None,
120 }
121 }
122 $v fn is_recognized(self) -> bool {
124 match self {
125 $( $name::$id => true, )*
126 _ => false
127 }
128 }
129 $v fn from_name(name: &str) -> Option<Self> {
131 match name {
132 $( stringify!($id) => Some($name::$id), )*
133 _ => None
134 }
135 }
136 fn get(self) -> $numtype {
138 self.into()
139 }
140 }
141 impl std::fmt::Display for $name {
142 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
143 match self.to_str() {
144 Some(s) => write!(f, "{}", s),
145 None => write!(f, "{}", self.0),
146 }
147 }
148 }
149 impl std::fmt::Debug for $name {
151 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
152 write!(f, "{}({})", stringify!($name), self)
153 }
154 }
155 };
156
157}