File tree Expand file tree Collapse file tree 2 files changed +33
-0
lines changed Expand file tree Collapse file tree 2 files changed +33
-0
lines changed Original file line number Diff line number Diff line change
1
+ //! Freestanding version of `std::default::Default::default()`.
2
+
3
+ /// Freestanding version of `std::default::Default::default()`.
4
+ ///
5
+ /// Used to be available under `#![feature(default_free_fn)]`,
6
+ /// removed in https://github.com/rust-lang/rust/pull/113469.
7
+ ///
8
+ /// # Examples
9
+ ///
10
+ /// ```
11
+ /// use stdext::prelude::*;
12
+ ///
13
+ /// #[derive(Default, PartialEq, Eq, Debug)]
14
+ /// struct StructWithLongName {
15
+ /// a: u32,
16
+ /// b: u32,
17
+ /// }
18
+ ///
19
+ /// let s = StructWithLongName {
20
+ /// a: 12,
21
+ /// ..default() // Normally you have to do
22
+ /// // `Default::default()`,
23
+ /// // `<_>::default()` or
24
+ /// // `StructWithLongName::default()`
25
+ /// };
26
+ ///
27
+ /// assert_eq!(s, StructWithLongName { a: 12, ..<_>::default() });
28
+ /// ```
29
+ pub fn default < T : Default > ( ) -> T {
30
+ T :: default ( )
31
+ }
Original file line number Diff line number Diff line change 132
132
pub mod duration;
133
133
#[ macro_use]
134
134
pub mod macros;
135
+ pub mod default;
135
136
pub mod num;
136
137
pub mod option;
137
138
pub mod result;
@@ -142,6 +143,7 @@ pub mod vec;
142
143
/// A "prelude" module which re-exports all the extension traits for the simple library usage.
143
144
pub mod prelude {
144
145
pub use crate :: {
146
+ default:: * ,
145
147
duration:: * ,
146
148
num:: { float_convert:: * , integer:: * } ,
147
149
option:: * ,
You can’t perform that action at this time.
0 commit comments