-
Notifications
You must be signed in to change notification settings - Fork 152
Expand file tree
/
Copy pathmod.rs
More file actions
57 lines (53 loc) · 1.26 KB
/
Copy pathmod.rs
File metadata and controls
57 lines (53 loc) · 1.26 KB
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
use derive_more::Error;
/// Derives `std::fmt::Display` for structs/enums.
/// Derived implementation outputs empty string.
/// Useful, as a way to formally satisfy `Display` trait bound.
///
/// ## Syntax:
///
/// For regular structs/enums:
///
/// ```
/// enum MyEnum {
/// ...
/// }
///
/// derive_display!(MyEnum);
/// ```
///
/// For generic structs/enums:
///
/// ```
/// struct MyGenericStruct<T, U> {
/// ...
/// }
///
/// derive_display!(MyGenericStruct, T, U);
/// ```
macro_rules! derive_display {
(@fmt) => {
fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
write!(f, "")
}
};
($type:ident) => {
impl ::core::fmt::Display for $type {
derive_display!(@fmt);
}
};
($type:ident, $($type_parameters:ident),*) => {
impl<$($type_parameters),*> ::core::fmt::Display for $type<$($type_parameters),*> {
derive_display!(@fmt);
}
};
}
mod derives_for_enums_with_source;
mod derives_for_generic_enums_with_source;
mod derives_for_generic_structs_with_source;
mod derives_for_structs_with_source;
mod derives_forward;
#[cfg(all(feature = "std", nightly))]
mod nightly;
derive_display!(SimpleErr);
#[derive(Default, Debug, Error)]
struct SimpleErr;