mirror of https://git.sr.ht/~stygianentity/bincode
Implement Default for Configuration (#575)
This commit is contained in:
parent
e3f7d5340e
commit
c763e2f11e
|
|
@ -46,6 +46,16 @@ pub struct Configuration<E = LittleEndian, I = Varint, A = WriteFixedArrayLength
|
||||||
_l: PhantomData<L>,
|
_l: PhantomData<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<T> 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:
|
/// The default config for bincode 2.0. By default this will be:
|
||||||
/// - Little endian
|
/// - Little endian
|
||||||
/// - Variable int encoding
|
/// - Variable int encoding
|
||||||
|
|
@ -62,7 +72,13 @@ pub const fn legacy() -> Configuration<LittleEndian, Fixint, WriteFixedArrayLeng
|
||||||
generate()
|
generate()
|
||||||
}
|
}
|
||||||
|
|
||||||
const fn generate<_E, _I, _A, _L>() -> Configuration<_E, _I, _A, _L> {
|
impl<E, I, A, L> Default for Configuration<E, I, A, L> {
|
||||||
|
fn default() -> Self {
|
||||||
|
generate()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const fn generate<E, I, A, L>() -> Configuration<E, I, A, L> {
|
||||||
Configuration {
|
Configuration {
|
||||||
_e: PhantomData,
|
_e: PhantomData,
|
||||||
_i: 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<T> 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<E, I, A, L> Configuration<E, I, A, L> {
|
impl<E, I, A, L> Configuration<E, I, A, L> {
|
||||||
/// Makes bincode encode all integer types in big endian.
|
/// Makes bincode encode all integer types in big endian.
|
||||||
pub const fn with_big_endian(self) -> Configuration<BigEndian, I, A, L> {
|
pub const fn with_big_endian(self) -> Configuration<BigEndian, I, A, L> {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue