Skip to content

Commit

Permalink
Remove unused Debug derives/impls.
Browse files Browse the repository at this point in the history
  • Loading branch information
caibear committed Mar 23, 2024
1 parent cdab168 commit 45e9431
Show file tree
Hide file tree
Showing 20 changed files with 26 additions and 57 deletions.
4 changes: 2 additions & 2 deletions src/bool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::fast::{CowSlice, NextUnchecked, PushUnchecked, SliceImpl, Unaligned,
use crate::pack::{pack_bools, unpack_bools};
use std::num::NonZeroUsize;

#[derive(Debug, Default)]
#[derive(Default)]
pub struct BoolEncoder(VecImpl<bool>);

impl Encoder<bool> for BoolEncoder {
Expand All @@ -29,7 +29,7 @@ impl Buffer for BoolEncoder {
}
}

#[derive(Debug, Default)]
#[derive(Default)]
pub struct BoolDecoder<'a>(CowSlice<'a, bool>);

impl<'a> View<'a> for BoolDecoder<'a> {
Expand Down
2 changes: 0 additions & 2 deletions src/derive/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use crate::fast::{FastSlice, FastVec, Unaligned};
use std::mem::MaybeUninit;
use std::num::NonZeroUsize;

#[derive(Debug)]
pub struct ArrayEncoder<T: Encode, const N: usize>(T::Encoder);

// Can't derive since it would bound T: Default.
Expand Down Expand Up @@ -59,7 +58,6 @@ impl<T: Encode, const N: usize> Buffer for ArrayEncoder<T, N> {
}
}

#[derive(Debug)]
pub struct ArrayDecoder<'a, T: Decode<'a>, const N: usize>(T::Decoder);

// Can't derive since it would bound T: Default.
Expand Down
2 changes: 1 addition & 1 deletion src/derive/empty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::coder::{Buffer, Decoder, Encoder, Result, View};
use std::marker::PhantomData;
use std::num::NonZeroUsize;

#[derive(Debug, Default)]
#[derive(Default)]
pub struct EmptyCoder;

impl<T> Encoder<PhantomData<T>> for EmptyCoder {
Expand Down
2 changes: 0 additions & 2 deletions src/derive/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,6 @@ macro_rules! impl_tuples {
type Encoder = TupleEncoder<$($name,)*>;
}

#[derive(Debug)]
pub struct TupleEncoder<$($name: Encode,)*>(
$($name::Encoder,)*
);
Expand Down Expand Up @@ -235,7 +234,6 @@ macro_rules! impl_tuples {
type Decoder = TupleDecoder<'a, $($name,)*>;
}

#[derive(Debug)]
pub struct TupleDecoder<'a, $($name: Decode<'a>,)*>(
$($name::Decoder,)*
std::marker::PhantomData<&'a ()>,
Expand Down
2 changes: 0 additions & 2 deletions src/derive/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use std::collections::{BTreeMap, HashMap};
use std::hash::{BuildHasher, Hash};
use std::num::NonZeroUsize;

#[derive(Debug)]
pub struct MapEncoder<K: Encode, V: Encode> {
lengths: LengthEncoder,
keys: K::Encoder,
Expand Down Expand Up @@ -36,7 +35,6 @@ impl<K: Encode, V: Encode> Buffer for MapEncoder<K, V> {
}
}

#[derive(Debug)]
pub struct MapDecoder<'a, K: Decode<'a>, V: Decode<'a>> {
lengths: LengthDecoder<'a>,
keys: K::Decoder,
Expand Down
2 changes: 0 additions & 2 deletions src/derive/option.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use crate::fast::{FastArrayVec, PushUnchecked};
use std::mem::MaybeUninit;
use std::num::NonZeroUsize;

#[derive(Debug)]
pub struct OptionEncoder<T: Encode> {
variants: VariantEncoder<2>,
some: T::Encoder,
Expand Down Expand Up @@ -85,7 +84,6 @@ impl<T: Encode> Buffer for OptionEncoder<T> {
}
}

#[derive(Debug)]
pub struct OptionDecoder<'a, T: Decode<'a>> {
variants: VariantDecoder<'a, 2, false>,
some: T::Decoder,
Expand Down
2 changes: 0 additions & 2 deletions src/derive/result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use crate::error::Error;
use std::mem::MaybeUninit;
use std::num::NonZeroUsize;

#[derive(Debug)]
pub struct ResultEncoder<T: Encode, E: Encode> {
variants: VariantEncoder<2>,
ok: T::Encoder,
Expand Down Expand Up @@ -54,7 +53,6 @@ impl<T: Encode, E: Encode> Buffer for ResultEncoder<T, E> {
}
}

#[derive(Debug)]
pub struct ResultDecoder<'a, T: Decode<'a>, E: Decode<'a>> {
variants: VariantDecoder<'a, 2, false>,
ok: T::Decoder,
Expand Down
1 change: 0 additions & 1 deletion src/derive/smart_ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ impl<T: Encode + ?Sized> Buffer for DerefEncoder<T> {
}

/// Decodes a `T` and then converts it with [`From`]. For `T` -> `Box<T>` and `Vec<T>` -> `Box<[T]>`.
#[derive(Debug)]
pub struct FromDecoder<'a, T: Decode<'a>>(T::Decoder);

// Can't derive since it would bound T: Default.
Expand Down
15 changes: 7 additions & 8 deletions src/derive/variant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::fast::{CowSlice, NextUnchecked, PushUnchecked, VecImpl};
use crate::pack::{pack_bytes_less_than, unpack_bytes_less_than};
use std::num::NonZeroUsize;

#[derive(Debug, Default)]
#[derive(Default)]
pub struct VariantEncoder<const N: usize>(VecImpl<u8>);

impl<const N: usize> Encoder<u8> for VariantEncoder<N> {
Expand All @@ -25,7 +25,6 @@ impl<const N: usize> Buffer for VariantEncoder<N> {
}
}

#[derive(Debug)]
pub struct VariantDecoder<'a, const N: usize, const C_STYLE: bool> {
variants: CowSlice<'a, u8>,
histogram: [usize; N], // Not required if C_STYLE. TODO don't reserve space for it.
Expand Down Expand Up @@ -70,12 +69,12 @@ impl<'a, const N: usize, const C_STYLE: bool> Decoder<'a, u8> for VariantDecoder

#[cfg(test)]
mod tests {
use crate::{decode, encode};
use crate::{decode, encode, Decode, Encode};

#[allow(unused)]
#[test]
fn test_c_style_enum() {
#[derive(crate::Encode, crate::Decode)]
#[derive(Encode, Decode)]
enum Enum1 {
A,
B,
Expand All @@ -84,7 +83,7 @@ mod tests {
E,
F,
}
#[derive(crate::Decode)]
#[derive(Decode)]
enum Enum2 {
A,
B,
Expand All @@ -101,7 +100,7 @@ mod tests {
#[allow(unused)]
#[test]
fn test_rust_style_enum() {
#[derive(crate::Encode, crate::Decode)]
#[derive(Encode, Decode)]
enum Enum1 {
A(u8),
B,
Expand All @@ -110,7 +109,7 @@ mod tests {
E,
F,
}
#[derive(crate::Decode)]
#[derive(Decode)]
enum Enum2 {
A(u8),
B,
Expand All @@ -124,7 +123,7 @@ mod tests {
assert!(matches!(decode(&encode(&Enum1::F)), Ok(Enum1::F)));
}

#[derive(Debug, PartialEq, crate::Encode, crate::Decode)]
#[derive(Debug, PartialEq, Encode, Decode)]
enum BoolEnum {
True,
False,
Expand Down
2 changes: 0 additions & 2 deletions src/derive/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use std::hash::{BuildHasher, Hash};
use std::mem::MaybeUninit;
use std::num::NonZeroUsize;

#[derive(Debug)]
pub struct VecEncoder<T: Encode> {
// pub(crate) for arrayvec.rs
pub(crate) lengths: LengthEncoder,
Expand Down Expand Up @@ -199,7 +198,6 @@ impl<T: Encode> Encoder<[T]> for VecEncoder<T> {
}
}

#[derive(Debug)]
pub struct VecDecoder<'a, T: Decode<'a>> {
// pub(crate) for arrayvec::ArrayVec.
pub(crate) lengths: LengthDecoder<'a>,
Expand Down
4 changes: 2 additions & 2 deletions src/f32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::fast::{FastSlice, NextUnchecked, PushUnchecked, VecImpl};
use std::mem::MaybeUninit;
use std::num::NonZeroUsize;

#[derive(Debug, Default)]
#[derive(Default)]
pub struct F32Encoder(VecImpl<f32>);

impl Encoder<f32> for F32Encoder {
Expand Down Expand Up @@ -80,7 +80,7 @@ impl Buffer for F32Encoder {
}
}

#[derive(Debug, Default)]
#[derive(Default)]
pub struct F32Decoder<'a> {
// While it is true that this contains 1 bit of the exp we still call it mantissa.
mantissa: FastSlice<'a, [u8; 3]>,
Expand Down
15 changes: 1 addition & 14 deletions src/fast.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use std::fmt::{Debug, Formatter};
use std::marker::PhantomData;
use std::mem::{ManuallyDrop, MaybeUninit};

Expand All @@ -13,12 +12,6 @@ pub struct FastVec<T> {
_spooky: PhantomData<Vec<T>>,
}

impl<T: Debug> Debug for FastVec<T> {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
self.as_slice().fmt(f)
}
}

impl<T> Default for FastVec<T> {
fn default() -> Self {
Self::from(vec![])
Expand Down Expand Up @@ -220,12 +213,6 @@ pub struct FastSlice<'a, T> {
_spooky: PhantomData<&'a T>,
}

impl<T: Debug> Debug for FastSlice<'_, T> {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
f.write_str("FastSlice") // We don't have len so we can't debug elements.
}
}

impl<T> Default for FastSlice<'_, T> {
fn default() -> Self {
Self::from([].as_slice())
Expand Down Expand Up @@ -344,7 +331,7 @@ impl<'a, T: Copy> NextUnchecked<'a, T> for &'a [T] {
}

/// Maybe owned [`FastSlice`]. Saves its allocation even if borrowing something.
#[derive(Debug, Default)]
#[derive(Default)]
pub struct CowSlice<'borrowed, T> {
slice: SliceImpl<'borrowed, T>, // Lifetime is min of 'borrowed and &'me self.
vec: Vec<T>,
Expand Down
4 changes: 2 additions & 2 deletions src/int.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use bytemuck::{CheckedBitPattern, NoUninit, Pod};
use std::marker::PhantomData;
use std::num::NonZeroUsize;

#[derive(Debug, Default)]
#[derive(Default)]
pub struct IntEncoder<T>(VecImpl<T>);

/// Makes IntEncoder<u32> able to encode i32/f32/char.
Expand Down Expand Up @@ -38,7 +38,7 @@ impl<T: Int> Buffer for IntEncoder<T> {
}
}

#[derive(Debug, Default)]
#[derive(Default)]
pub struct IntDecoder<'a, T: Int>(CowSlice<'a, T::Une>);

impl<'a, T: Int> IntDecoder<'a, T> {
Expand Down
4 changes: 2 additions & 2 deletions src/length.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::int::{IntDecoder, IntEncoder};
use crate::pack::{pack_bytes, unpack_bytes};
use std::num::NonZeroUsize;

#[derive(Debug, Default)]
#[derive(Default)]
pub struct LengthEncoder {
small: VecImpl<u8>,
large: IntEncoder<usize>,
Expand Down Expand Up @@ -109,7 +109,7 @@ impl Buffer for LengthEncoder {
}
}

#[derive(Debug, Default)]
#[derive(Default)]
pub struct LengthDecoder<'a> {
small: CowSlice<'a, u8>,
large: IntDecoder<'a, usize>,
Expand Down
7 changes: 3 additions & 4 deletions src/pack_ints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -477,10 +477,9 @@ fn unpack_ints_sized_unsigned<'a, T: SizedUInt>(
mod tests {
use super::{usize_too_big, CowSlice, Int, Result};
use crate::error::err;
use std::fmt::Debug;
use test::{black_box, Bencher};

pub fn pack_ints<T: Int + Debug>(ints: &[T]) -> Vec<u8> {
pub fn pack_ints<T: Int>(ints: &[T]) -> Vec<u8> {
let mut out = vec![];
super::pack_ints(&mut ints.to_vec(), &mut out);
assert_eq!(ints, unpack_ints(&out, ints.len()).unwrap());
Expand Down Expand Up @@ -563,7 +562,7 @@ mod tests {
);
}

fn test_inner<T: Int + Debug>(ints: &[T]) -> Vec<u8> {
fn test_inner<T: Int>(ints: &[T]) -> Vec<u8> {
let out = pack_ints(&mut ints.to_owned());
let unpacked = unpack_ints::<T>(&out, ints.len()).unwrap();
assert_eq!(unpacked, ints);
Expand Down Expand Up @@ -636,7 +635,7 @@ mod tests {
assert_eq!(out.capacity(), starting_cap);
}

fn bench_unpack_ints<T: Int + Debug>(b: &mut Bencher, src: &[T]) {
fn bench_unpack_ints<T: Int>(b: &mut Bencher, src: &[T]) {
let packed = pack_ints(&mut src.to_vec());
let mut out = CowSlice::with_allocation(Vec::<T::Une>::with_capacity(src.len()));
b.iter(|| {
Expand Down
1 change: 0 additions & 1 deletion src/serde/de.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ mod inner {
}
pub use inner::deserialize;

#[derive(Debug)]
enum SerdeDecoder<'a> {
Bool(BoolDecoder<'a>),
Enum((VariantDecoder<'a>, Vec<SerdeDecoder<'a>>)), // (variants, values)
Expand Down
2 changes: 0 additions & 2 deletions src/serde/ser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ mod inner {
}
pub use inner::serialize;

#[derive(Debug)]
enum SpecifiedEncoder {
Bool(BoolEncoder),
Enum((VariantEncoder, Vec<LazyEncoder>)), // (variants, values)
Expand Down Expand Up @@ -110,7 +109,6 @@ impl SpecifiedEncoder {
}
}

#[derive(Debug)]
enum LazyEncoder {
Unspecified {
reserved: Option<NonZeroUsize>,
Expand Down
4 changes: 2 additions & 2 deletions src/serde/variant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::pack::{pack_bytes, unpack_bytes};
use std::marker::PhantomData;
use std::num::NonZeroUsize;

#[derive(Debug, Default)]
#[derive(Default)]
pub struct VariantEncoder {
data: VecImpl<u8>,
}
Expand All @@ -27,7 +27,7 @@ impl Buffer for VariantEncoder {
}
}

#[derive(Debug, Default)]
#[derive(Default)]
pub struct VariantDecoder<'a> {
variants: CowSlice<'a, u8>,
histogram: Vec<usize>,
Expand Down
4 changes: 2 additions & 2 deletions src/str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::u8_char::U8Char;
use std::num::NonZeroUsize;
use std::str::{from_utf8, from_utf8_unchecked};

#[derive(Debug, Default)]
#[derive(Default)]
pub struct StrEncoder(pub(crate) VecEncoder<U8Char>); // pub(crate) for arrayvec.rs

#[inline(always)]
Expand Down Expand Up @@ -70,7 +70,7 @@ impl Encoder<String> for StrEncoder {
}

// Doesn't use VecDecoder because can't decode &[u8].
#[derive(Debug, Default)]
#[derive(Default)]
pub struct StrDecoder<'a> {
// pub(crate) for arrayvec::ArrayString.
pub(crate) lengths: LengthDecoder<'a>,
Expand Down
Loading

0 comments on commit 45e9431

Please sign in to comment.