Skip to content

Commit

Permalink
Use const functions where possible (#684)
Browse files Browse the repository at this point in the history
  • Loading branch information
richardpringle authored Dec 14, 2023
1 parent ff7a45a commit 3a638a7
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/de/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub struct DecoderImpl<R, C: Config> {

impl<R: Reader, C: Config> DecoderImpl<R, C> {
/// 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 {
reader,
config,
Expand Down
2 changes: 1 addition & 1 deletion src/de/read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ pub struct SliceReader<'storage> {

impl<'storage> SliceReader<'storage> {
/// Constructs a slice reader
pub fn new(bytes: &'storage [u8]) -> SliceReader<'storage> {
pub const fn new(bytes: &'storage [u8]) -> SliceReader<'storage> {
SliceReader { slice: bytes }
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/enc/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub struct EncoderImpl<W: Writer, C: Config> {

impl<W: Writer, C: Config> EncoderImpl<W, C> {
/// 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 }
}

Expand Down
2 changes: 1 addition & 1 deletion src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ pub enum IntegerType {
impl IntegerType {
/// Change the `Ux` value to the associated `Ix` value.
/// 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 {
Self::U8 => Self::I8,
Self::U16 => Self::I16,
Expand Down
4 changes: 2 additions & 2 deletions src/features/impl_std.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ pub(crate) struct IoReader<R> {
}

impl<R> IoReader<R> {
pub fn new(reader: R) -> Self {
pub const fn new(reader: R) -> Self {
Self { reader }
}
}
Expand Down Expand Up @@ -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
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/varint/decode_unsigned.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ where

#[inline(never)]
#[cold]
fn invalid_varint_discriminant<T>(
const fn invalid_varint_discriminant<T>(
expected: IntegerType,
found: IntegerType,
) -> Result<T, DecodeError> {
Expand Down

0 comments on commit 3a638a7

Please sign in to comment.