Skip to content

Commit

Permalink
Merge pull request #2 from bsodmike/wip/next_release_v3.0.0
Browse files Browse the repository at this point in the history
Release v3.0.0
  • Loading branch information
bsodmike authored Sep 8, 2024
2 parents 0254aef + 09ab118 commit 91a6938
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 10 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

# Unreleased

# 3.0.0 (8 Sept 2024)

- **fixed:** Impl `std::error::Error` for the crates default error type.

# 2.0.0 (8 Sept 2024)

- **added:** Github CI
Expand All @@ -16,7 +20,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

See [PR for changes](https://github.com/bsodmike/better-limit-reader-rs/pull/1/files)


# 1.0.2 (7 Sept 2024)

- **changed:** Add enhancement task to README
Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "better-limit-reader"
version = "2.0.0"
version = "3.0.0"
authors = ["Michael de Silva <michael@cyberdynea.io>"]
description = "Configurable limit reader that limits the number of bytes read from an underlying reader, supporting decompression from Gzip and Zlib compressed via `flate2`"
readme = "README.md"
Expand Down
19 changes: 13 additions & 6 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@ use std::{
#[allow(clippy::module_name_repetitions)]
pub type BoxError = Box<dyn StdError + Send + Sync>;

/// Default error type for create.
#[allow(clippy::module_name_repetitions)]
pub type LimitReaderError = Error;

/// Error type
pub struct Error {
kind: ErrorKind,
Expand All @@ -25,11 +21,11 @@ pub struct Error {
#[allow(clippy::module_name_repetitions)]
#[allow(clippy::enum_variant_names)]
pub enum ErrorKind {
ReadError,
IoError,
LimitReaderOutputBuilderError,
Utf8Error,
TryFromIntError,
LimitReaderError(Box<dyn StdError + Send + Sync>),
}

impl ErrorKind {
Expand All @@ -38,11 +34,11 @@ impl ErrorKind {
use ErrorKind::*;
// tidy-alphabetical-start
match *self {
ReadError => "read error",
IoError => "io error",
Utf8Error => "invalid utf-8",
LimitReaderOutputBuilderError => "builder error",
TryFromIntError => "conversion error",
LimitReaderError(_) => "boxed error",
}
}
}
Expand All @@ -54,6 +50,13 @@ impl fmt::Display for ErrorKind {
}
}

impl StdError for Error {
fn source(&self) -> Option<&(dyn StdError + 'static)> {
Some(&*self.error)
}
}

#[allow(dead_code)]
impl Error {
pub fn new<E>(kind: ErrorKind, error: E) -> Error
where
Expand Down Expand Up @@ -107,3 +110,7 @@ pub mod macros {
};
}
}

/// Default error for [`crate::prelude::LimitReader`]
#[allow(clippy::module_name_repetitions)]
pub type LimitReaderError = Error;
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ impl LimitReader {
let try_read = reader.perform_read(&mut self.buf);
match try_read {
Ok(value) => Ok(value),
Err(err) => Err(LimitReaderError::new(error::ErrorKind::IoError, err)),
Err(err) => Err(LimitReaderError::new(error::ErrorKind::ReadError, err)),
}
}
}
Expand Down

0 comments on commit 91a6938

Please sign in to comment.