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
//! This module is not considered public api.
//!
//! But since the derive macros need to have access to its content it is all public.
//! Anyway feel free to look at and maybe even use it.
pub use imr;
/// Wrap a `Fn(&mut std::fmt::Formatter<'_>) -> std::fmt::Result` to implement [`Display`](std::fmt::Display)
;
/// Provides a `'static` reference to a / "the" value of `Self`
///
/// This trait is a double workaround:
/// 1. The is no const equivalent for [`Default`] because const functions are not stable
/// 2. If 1 were fixed, one could not create a constant / static
/// reference to this default value in a generic context:
///
/// ```no_compile
/// // Workaround for 1
/// trait ConstDefault {
/// const DEFAULT: Self;
/// }
///
/// fn using_statics<T: ConstDefault>() -> &'static T {
/// static INSTANCE: T = T::DEFAULT; // <- Can't use generics in statics
/// &INSTANCE
/// }
/// fn using_consts<T: ConstDefault>() -> &'static T {
/// const INSTANCE: T = T::DEFAULT; // <- Can't store potentially interior mutable data in consts
/// &INSTANCE
/// }
/// ```
///
/// However, if the type `T` is not generic but known, then both functions would work without a problem.
/// This trait can't be implemented generically because this trait's implementor has to write one of the functions above.
/// Since this trait needs to be usable in a const context,
/// the reference must be assigned to a constant and can't be returned from a function.
///
/// This trait hopefully becomes obsolete once `Freeze` is stabilized.