mirror of https://git.sr.ht/~stygianentity/bincode
Use const functions where possible (#684)
This commit is contained in:
parent
b31bb67c59
commit
8f3f84ae94
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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 }
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 }
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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 }
|
||||
}
|
||||
}
|
||||
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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> {
|
||||
|
|
|
|||
Loading…
Reference in New Issue