From c763e2f11e046cc6f5aa27ad44204904b59bc7ee Mon Sep 17 00:00:00 2001 From: Trangar Date: Thu, 18 Aug 2022 19:14:07 +0200 Subject: [PATCH] Implement Default for Configuration (#575) --- src/config.rs | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/src/config.rs b/src/config.rs index 055faec..b5b3637 100644 --- a/src/config.rs +++ b/src/config.rs @@ -46,6 +46,16 @@ pub struct Configuration, } +// When adding more features to configuration, follow these steps: +// - Create 2 or more structs that can be used as a type (e.g. Limit and NoLimit) +// - Add an `Internal...Config` to the `internal` module +// - Make sure `Config` and `impl Config for T` extend from this new trait +// - Add a generic to `Configuration` +// - Add this generic to `impl<...> Default for Configuration<...>` +// - Add this generic to `const fn generate<...>()` +// - Add this generic to _every_ function in `Configuration` +// - Add your new methods + /// The default config for bincode 2.0. By default this will be: /// - Little endian /// - Variable int encoding @@ -62,7 +72,13 @@ pub const fn legacy() -> Configuration() -> Configuration<_E, _I, _A, _L> { +impl Default for Configuration { + fn default() -> Self { + generate() + } +} + +const fn generate() -> Configuration { Configuration { _e: PhantomData, _i: PhantomData, @@ -71,15 +87,6 @@ const fn generate<_E, _I, _A, _L>() -> Configuration<_E, _I, _A, _L> { } } -// When adding more features to configuration, follow these steps: -// - Create 2 or more structs that can be used as a type (e.g. Limit and NoLimit) -// - Add an `Internal...Config` to the `internal` module -// - Make sure `Config` and `impl Config for T` extend from this new trait -// - Add a generic to `Configuration` -// - Add this generic to `const fn generate<...>()` -// - Add this generic to _every_ function in `Configuration` -// - Add your new methods - impl Configuration { /// Makes bincode encode all integer types in big endian. pub const fn with_big_endian(self) -> Configuration {