Skip to content

Commit 4837312

Browse files
committed
deps: remove thiserror, impl Error manually
Before: ``` $ cargo tree --edges build,normal bcs v0.1.6 (/home/phlip9/dev/bcs) ├── serde v1.0.228 │ ├── serde_core v1.0.228 │ └── serde_derive v1.0.228 (proc-macro) │ ├── proc-macro2 v1.0.106 │ │ └── unicode-ident v1.0.24 │ ├── quote v1.0.45 │ │ └── proc-macro2 v1.0.106 (*) │ └── syn v2.0.117 │ ├── proc-macro2 v1.0.106 (*) │ ├── quote v1.0.45 (*) │ └── unicode-ident v1.0.24 └── thiserror v1.0.69 └── thiserror-impl v1.0.69 (proc-macro) ├── proc-macro2 v1.0.106 (*) ├── quote v1.0.45 (*) └── syn v2.0.117 (*) $ rm -rf /tmp/cargo-target && taskset -c 3 cargo build --target-dir /tmp/cargo-target --lib Finished dev [unoptimized + debuginfo] target(s) in 7.89s ``` After: ``` $ cargo tree --edges build,normal Updating crates.io index bcs v0.1.6 (/home/phlip9/dev/bcs) └── serde_core v1.0.228 $ rm -rf /tmp/cargo-target && taskset -c 3 cargo build --target-dir /tmp/cargo-target --lib Compiling serde_core v1.0.228 Compiling bcs v0.1.6 (/home/phlip9/dev/bcs) Finished dev [unoptimized + debuginfo] target(s) in 1.38s ```
1 parent 56f4d42 commit 4837312

2 files changed

Lines changed: 34 additions & 19 deletions

File tree

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ license = "Apache-2.0"
88
edition = "2018"
99

1010
[dependencies]
11-
thiserror = "1.0.37"
1211
serde_core = { version = "1", default-features = false }
1312

1413
[dev-dependencies]

src/error.rs

Lines changed: 34 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,46 +3,62 @@
33

44
use serde_core::{de, ser};
55
use std::{fmt, io::ErrorKind};
6-
use thiserror::Error;
76

87
pub type Result<T, E = Error> = std::result::Result<T, E>;
98

10-
#[derive(Clone, Debug, Error, Eq, PartialEq)]
9+
#[derive(Clone, Debug, Eq, PartialEq)]
1110
pub enum Error {
12-
#[error("unexpected end of input")]
1311
Eof,
14-
#[error("I/O error: {0}")]
1512
Io(String),
16-
#[error("exceeded max sequence length: {0}")]
1713
ExceededMaxLen(usize),
18-
#[error("exceeded max container depth while entering: {0}")]
1914
ExceededContainerDepthLimit(&'static str),
20-
#[error("expected boolean")]
2115
ExpectedBoolean,
22-
#[error("expected map key")]
2316
ExpectedMapKey,
24-
#[error("expected map value")]
2517
ExpectedMapValue,
26-
#[error("keys of serialized maps must be unique and in increasing order")]
2718
NonCanonicalMap,
28-
#[error("expected option type")]
2919
ExpectedOption,
30-
#[error("{0}")]
3120
Custom(String),
32-
#[error("sequence missing length")]
3321
MissingLen,
34-
#[error("not supported: {0}")]
3522
NotSupported(&'static str),
36-
#[error("remaining input")]
3723
RemainingInput,
38-
#[error("malformed utf8")]
3924
Utf8,
40-
#[error("ULEB128 encoding was not minimal in size")]
4125
NonCanonicalUleb128Encoding,
42-
#[error("ULEB128-encoded integer did not fit in the target size")]
4326
IntegerOverflowDuringUleb128Decoding,
4427
}
4528

29+
impl std::error::Error for Error {}
30+
31+
impl fmt::Display for Error {
32+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
33+
match self {
34+
Self::Eof => f.write_str("unexpected end of input"),
35+
Self::Io(err) => write!(f, "I/O error: {err}"),
36+
Self::ExceededMaxLen(len) => write!(f, "exceeded max sequence length: {len}"),
37+
Self::ExceededContainerDepthLimit(ty) => {
38+
write!(f, "exceeded max container depth while entering: {ty}")
39+
}
40+
Self::ExpectedBoolean => f.write_str("expected boolean"),
41+
Self::ExpectedMapKey => f.write_str("expected map key"),
42+
Self::ExpectedMapValue => f.write_str("expected map value"),
43+
Self::NonCanonicalMap => {
44+
f.write_str("keys of serialized maps must be unique and in increasing order")
45+
}
46+
Self::ExpectedOption => f.write_str("expected option type"),
47+
Self::Custom(msg) => f.write_str(msg),
48+
Self::MissingLen => f.write_str("sequence missing length"),
49+
Self::NotSupported(msg) => write!(f, "not supported: {msg}"),
50+
Self::RemainingInput => f.write_str("remaining input"),
51+
Self::Utf8 => f.write_str("malformed utf8"),
52+
Self::NonCanonicalUleb128Encoding => {
53+
f.write_str("ULEB128 encoding was not minimal in size")
54+
}
55+
Self::IntegerOverflowDuringUleb128Decoding => {
56+
f.write_str("ULEB128-encoded integer did not fit in the target size")
57+
}
58+
}
59+
}
60+
}
61+
4662
impl From<std::io::Error> for Error {
4763
fn from(err: std::io::Error) -> Self {
4864
if err.kind() == ErrorKind::UnexpectedEof {

0 commit comments

Comments
 (0)