From dbb9a43ccd956f674284f207212ead8f2af37ef1 Mon Sep 17 00:00:00 2001 From: Popog <761307+Popog@users.noreply.github.com> Date: Thu, 16 Dec 2021 00:53:15 -0800 Subject: [PATCH] feat: Make `Configuration` functions `const` (#456) --- src/config.rs | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/config.rs b/src/config.rs index aec6a07..d8ffc53 100644 --- a/src/config.rs +++ b/src/config.rs @@ -52,7 +52,7 @@ impl Configuration { /// - Little endian /// - Variable int encoding /// - Skip fixed array length - pub fn standard() -> Self { + pub const fn standard() -> Self { Self::generate() } @@ -60,13 +60,13 @@ impl Configuration { /// - Little endian /// - Fixed int length encoding /// - Write array lengths - pub fn legacy() -> Configuration { + pub const fn legacy() -> Configuration { Self::generate() } } impl Configuration { - fn generate<_E, _I, _A, _L>() -> Configuration<_E, _I, _A, _L> { + const fn generate<_E, _I, _A, _L>() -> Configuration<_E, _I, _A, _L> { Configuration { _e: PhantomData, _i: PhantomData, @@ -76,12 +76,12 @@ impl Configuration { } /// Makes bincode encode all integer types in big endian. - pub fn with_big_endian(self) -> Configuration { + pub const fn with_big_endian(self) -> Configuration { Self::generate() } /// Makes bincode encode all integer types in little endian. - pub fn with_little_endian(self) -> Configuration { + pub const fn with_little_endian(self) -> Configuration { Self::generate() } @@ -142,7 +142,7 @@ impl Configuration { /// /// Note that u256 and the like are unsupported by this format; if and when they are added to the /// language, they may be supported via the extension point given by the 255 byte. - pub fn with_variable_int_encoding(self) -> Configuration { + pub const fn with_variable_int_encoding(self) -> Configuration { Self::generate() } @@ -151,27 +151,27 @@ impl Configuration { /// * Fixed size integers are encoded directly /// * Enum discriminants are encoded as u32 /// * Lengths and usize are encoded as u64 - pub fn with_fixed_int_encoding(self) -> Configuration { + pub const fn with_fixed_int_encoding(self) -> Configuration { Self::generate() } /// Skip writing the length of fixed size arrays (`[u8; N]`) before writing the array - pub fn skip_fixed_array_length(self) -> Configuration { + pub const fn skip_fixed_array_length(self) -> Configuration { Self::generate() } /// Write the length of fixed size arrays (`[u8; N]`) before writing the array - pub fn write_fixed_array_length(self) -> Configuration { + pub const fn write_fixed_array_length(self) -> Configuration { Self::generate() } /// Sets the byte limit to `limit`. - pub fn with_limit(self) -> Configuration> { + pub const fn with_limit(self) -> Configuration> { Self::generate() } /// Clear the byte limit. - pub fn with_no_limit(self) -> Configuration { + pub const fn with_no_limit(self) -> Configuration { Self::generate() } }