Skip to content

Commit

Permalink
fix: Implement Display and expose UpdateError
Browse files Browse the repository at this point in the history
  • Loading branch information
manokara committed Dec 31, 2020
1 parent da047f8 commit 8b390b3
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 3 deletions.
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [0.9.1]

### Changed

- Implement `Display` for `UpdateError`
- Expose `UpdateError` in the crate root

## [0.9.0] - 2020-12-31

### Added
Expand Down Expand Up @@ -106,7 +113,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Ref variants from Value
- Debug prints

[Unreleased]: https://github.com/manokara/bencode-rs/compare/v0.9.0...HEAD
[Unreleased]: https://github.com/manokara/bencode-rs/compare/v0.9.1...HEAD
[0.9.1]: https://github.com/manokara/bencode-rs/compare/v0.9.0...v0.9.1
[0.9.0]: https://github.com/manokara/bencode-rs/compare/v0.8.1...v0.9.0
[0.8.1]: https://github.com/manokara/bencode-rs/compare/v0.8.0...v0.8.1
[0.8.0]: https://github.com/manokara/bencode-rs/compare/v0.7.0...v0.8.0
Expand Down
20 changes: 18 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,22 @@ mod parser;
mod tests;
mod value;

pub use parser::{load, load_dict, load_list, load_prim, ParserError, Stream};
pub use parser::{
load,
load_dict,
load_list,
load_prim,
ParserError,
Stream,
};

pub use value::{
SelectError,
TraverseAction,
TraverseError,
UpdateError,
Value,
ValueAccessor,
ValueDisplay,
};

pub use value::{SelectError, TraverseAction, TraverseError, Value, ValueAccessor, ValueDisplay};
12 changes: 12 additions & 0 deletions src/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1062,6 +1062,18 @@ impl fmt::Display for SelectError {
}
}

impl fmt::Display for UpdateError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
UpdateError::Index => write!(f, "Index out of bounds"),
UpdateError::Key => write!(f, "Key doesn't exist"),
UpdateError::List => write!(f, "Container is a list"),
UpdateError::Dict => write!(f, "Container is a dictionary"),
UpdateError::Primitive => write!(f, "Value is a primitive"),
}
}
}

impl fmt::Display for Value {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
ValueDisplay::new(self).fmt(f)
Expand Down

0 comments on commit 8b390b3

Please sign in to comment.