Skip to content

Commit 5265c12

Browse files
authored
remove derive_more (#60)
* Initial go at things * Finish off Frame * Finish off removing all of derive_more * Fix clippy complaint * Actually fix CI!
1 parent 88f7a41 commit 5265c12

14 files changed

+1015
-244
lines changed

Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ categories = ["compression"]
1515
[dependencies]
1616
byteorder = { version = "1.5", default-features = false }
1717
twox-hash = { version = "1.6", default-features = false, optional = true }
18-
derive_more = { version = "0.99", default-features = false, features = ["display", "from"] }
1918

2019
[dev-dependencies]
2120
criterion = "0.5"
@@ -24,7 +23,7 @@ rand = { version = "0.8.5", features = ["small_rng"] }
2423
[features]
2524
default = ["hash", "std"]
2625
hash = ["dep:twox-hash"]
27-
std = ["derive_more/error"]
26+
std = []
2827

2928
[[bench]]
3029
name = "reversedbitreader_bench"

src/blocks/literals_section.rs

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,51 @@ pub enum LiteralsSectionType {
1414
Treeless,
1515
}
1616

17-
#[derive(Debug, derive_more::Display, derive_more::From)]
18-
#[cfg_attr(feature = "std", derive(derive_more::Error))]
17+
#[derive(Debug)]
1918
#[non_exhaustive]
2019
pub enum LiteralsSectionParseError {
21-
#[display(fmt = "Illegal literalssectiontype. Is: {got}, must be in: 0, 1, 2, 3")]
2220
IllegalLiteralSectionType { got: u8 },
23-
#[display(fmt = "{_0:?}")]
24-
#[from]
2521
GetBitsError(GetBitsError),
26-
#[display(
27-
fmt = "Not enough byte to parse the literals section header. Have: {have}, Need: {need}"
28-
)]
2922
NotEnoughBytes { have: usize, need: u8 },
3023
}
3124

25+
#[cfg(feature = "std")]
26+
impl std::error::Error for LiteralsSectionParseError {
27+
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
28+
match self {
29+
LiteralsSectionParseError::GetBitsError(source) => Some(source),
30+
_ => None,
31+
}
32+
}
33+
}
34+
impl core::fmt::Display for LiteralsSectionParseError {
35+
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
36+
match self {
37+
LiteralsSectionParseError::IllegalLiteralSectionType { got } => {
38+
write!(
39+
f,
40+
"Illegal literalssectiontype. Is: {}, must be in: 0, 1, 2, 3",
41+
got
42+
)
43+
}
44+
LiteralsSectionParseError::GetBitsError(e) => write!(f, "{:?}", e),
45+
LiteralsSectionParseError::NotEnoughBytes { have, need } => {
46+
write!(
47+
f,
48+
"Not enough byte to parse the literals section header. Have: {}, Need: {}",
49+
have, need,
50+
)
51+
}
52+
}
53+
}
54+
}
55+
56+
impl From<GetBitsError> for LiteralsSectionParseError {
57+
fn from(val: GetBitsError) -> Self {
58+
Self::GetBitsError(val)
59+
}
60+
}
61+
3262
impl core::fmt::Display for LiteralsSectionType {
3363
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> Result<(), core::fmt::Error> {
3464
match self {

src/blocks/sequence_section.rs

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,16 +55,29 @@ impl Default for SequencesHeader {
5555
}
5656
}
5757

58-
#[derive(Debug, derive_more::Display)]
59-
#[cfg_attr(feature = "std", derive(derive_more::Error))]
58+
#[derive(Debug)]
6059
#[non_exhaustive]
6160
pub enum SequencesHeaderParseError {
62-
#[display(
63-
fmt = "source must have at least {need_at_least} bytes to parse header; got {got} bytes"
64-
)]
6561
NotEnoughBytes { need_at_least: u8, got: usize },
6662
}
6763

64+
#[cfg(feature = "std")]
65+
impl std::error::Error for SequencesHeaderParseError {}
66+
67+
impl core::fmt::Display for SequencesHeaderParseError {
68+
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
69+
match self {
70+
SequencesHeaderParseError::NotEnoughBytes { need_at_least, got } => {
71+
write!(
72+
f,
73+
"source must have at least {} bytes to parse header; got {} bytes",
74+
need_at_least, got,
75+
)
76+
}
77+
}
78+
}
79+
}
80+
6881
impl SequencesHeader {
6982
pub fn new() -> SequencesHeader {
7083
SequencesHeader {

src/decoding/bit_reader.rs

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,47 @@ pub struct BitReader<'s> {
33
source: &'s [u8],
44
}
55

6-
#[derive(Debug, derive_more::Display)]
7-
#[cfg_attr(feature = "std", derive(derive_more::Error))]
6+
#[derive(Debug)]
87
#[non_exhaustive]
98
pub enum GetBitsError {
10-
#[display(
11-
fmt = "Cant serve this request. The reader is limited to {limit} bits, requested {num_requested_bits} bits"
12-
)]
139
TooManyBits {
1410
num_requested_bits: usize,
1511
limit: u8,
1612
},
17-
#[display(fmt = "Can't read {requested} bits, only have {remaining} bits left")]
18-
NotEnoughRemainingBits { requested: usize, remaining: usize },
13+
NotEnoughRemainingBits {
14+
requested: usize,
15+
remaining: usize,
16+
},
17+
}
18+
19+
#[cfg(feature = "std")]
20+
impl std::error::Error for GetBitsError {}
21+
22+
impl core::fmt::Display for GetBitsError {
23+
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
24+
match self {
25+
GetBitsError::TooManyBits {
26+
num_requested_bits,
27+
limit,
28+
} => {
29+
write!(
30+
f,
31+
"Cant serve this request. The reader is limited to {} bits, requested {} bits",
32+
limit, num_requested_bits,
33+
)
34+
}
35+
GetBitsError::NotEnoughRemainingBits {
36+
requested,
37+
remaining,
38+
} => {
39+
write!(
40+
f,
41+
"Can\'t read {} bits, only have {} bits left",
42+
requested, remaining,
43+
)
44+
}
45+
}
46+
}
1947
}
2048

2149
impl<'s> BitReader<'s> {

0 commit comments

Comments
 (0)