Use const functions where possible (#684)

This commit is contained in:
Richard Pringle 2023-12-14 05:56:51 -05:00 committed by GitHub
parent b31bb67c59
commit 8f3f84ae94
6 changed files with 7 additions and 7 deletions

View File

@ -28,7 +28,7 @@ pub struct DecoderImpl<R, C: Config> {
impl<R: Reader, C: Config> DecoderImpl<R, C> { impl<R: Reader, C: Config> DecoderImpl<R, C> {
/// Construct a new Decoder /// Construct a new Decoder
pub fn new(reader: R, config: C) -> DecoderImpl<R, C> { pub const fn new(reader: R, config: C) -> DecoderImpl<R, C> {
DecoderImpl { DecoderImpl {
reader, reader,
config, config,

View File

@ -66,7 +66,7 @@ pub struct SliceReader<'storage> {
impl<'storage> SliceReader<'storage> { impl<'storage> SliceReader<'storage> {
/// Constructs a slice reader /// Constructs a slice reader
pub fn new(bytes: &'storage [u8]) -> SliceReader<'storage> { pub const fn new(bytes: &'storage [u8]) -> SliceReader<'storage> {
SliceReader { slice: bytes } SliceReader { slice: bytes }
} }
} }

View File

@ -27,7 +27,7 @@ pub struct EncoderImpl<W: Writer, C: Config> {
impl<W: Writer, C: Config> EncoderImpl<W, C> { impl<W: Writer, C: Config> EncoderImpl<W, C> {
/// Create a new Encoder /// Create a new Encoder
pub fn new(writer: W, config: C) -> EncoderImpl<W, C> { pub const fn new(writer: W, config: C) -> EncoderImpl<W, C> {
EncoderImpl { writer, config } EncoderImpl { writer, config }
} }

View File

@ -250,7 +250,7 @@ pub enum IntegerType {
impl IntegerType { impl IntegerType {
/// Change the `Ux` value to the associated `Ix` value. /// Change the `Ux` value to the associated `Ix` value.
/// Returns the old value if `self` is already `Ix`. /// Returns the old value if `self` is already `Ix`.
pub(crate) fn into_signed(self) -> Self { pub(crate) const fn into_signed(self) -> Self {
match self { match self {
Self::U8 => Self::I8, Self::U8 => Self::I8,
Self::U16 => Self::I16, Self::U16 => Self::I16,

View File

@ -37,7 +37,7 @@ pub(crate) struct IoReader<R> {
} }
impl<R> IoReader<R> { impl<R> IoReader<R> {
pub fn new(reader: R) -> Self { pub const fn new(reader: R) -> Self {
Self { reader } Self { reader }
} }
} }
@ -109,7 +109,7 @@ impl<'a, W: std::io::Write> IoWriter<'a, W> {
} }
} }
pub fn bytes_written(&self) -> usize { pub const fn bytes_written(&self) -> usize {
self.bytes_written self.bytes_written
} }
} }

View File

@ -190,7 +190,7 @@ where
#[inline(never)] #[inline(never)]
#[cold] #[cold]
fn invalid_varint_discriminant<T>( const fn invalid_varint_discriminant<T>(
expected: IntegerType, expected: IntegerType,
found: IntegerType, found: IntegerType,
) -> Result<T, DecodeError> { ) -> Result<T, DecodeError> {