Debian Codegraph @

debian/missing-sources/derive_more/tests/error/mod.rs

raw
1 #[cfg(not(feature = "std"))]
2 extern crate alloc;
3
4 use derive_more::with_trait::Error;
5
6 /// Derives `std::fmt::Display` for structs/enums.
7 /// Derived implementation outputs empty string.
8 /// Useful, as a way to formally satisfy `Display` trait bound.
9 ///
10 /// ## Syntax:
11 ///
12 /// For regular structs/enums:
13 ///
14 /// ```
15 /// enum MyEnum {
16 /// ...
17 /// }
18 ///
19 /// derive_display!(MyEnum);
20 /// ```
21 ///
22 /// For generic structs/enums:
23 ///
24 /// ```
25 /// struct MyGenericStruct<T, U> {
26 /// ...
27 /// }
28 ///
29 /// derive_display!(MyGenericStruct, T, U);
30 /// ```
31 macro_rules! derive_display {
32 (@fmt) => {
33 fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
34 write!(f, "")
35 }
36 };
37 ($type:ident) => {
38 impl ::core::fmt::Display for $type {
39 derive_display!(@fmt);
40 }
41 };
42 ($type:ident, $($type_parameters:ident),*) => {
43 impl<$($type_parameters),*> ::core::fmt::Display for $type<$($type_parameters),*> {
44 derive_display!(@fmt);
45 }
46 };
47 }
48
49 mod derives_for_enums_with_source;
50 mod derives_for_generic_enums_with_source;
51 mod derives_for_generic_structs_with_source;
52 mod derives_for_structs_with_source;
53
54 #[cfg(all(feature = "std", nightly))]
55 mod nightly;
56
57 derive_display!(SimpleErr);
58 #[derive(Default, Debug, Error)]
59 struct SimpleErr;