Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rust: use displaydoc for Error type; MSRV 1.40+ #91

Merged
merged 1 commit into from
Feb 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
- thumbv7em-none-eabihf
- wasm32-unknown-unknown
toolchain:
- 1.39.0
- 1.40.0
- stable
steps:
- name: Checkout sources
Expand Down Expand Up @@ -138,7 +138,7 @@ jobs:
- macos-latest
- windows-latest
toolchain:
- 1.39.0
- 1.40.0
- stable
runs-on: ${{ matrix.platform }}
steps:
Expand Down
12 changes: 12 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ categories = ["authentication", "cryptography", "encoding"]
keywords = ["hashing", "merkle", "protobufs", "security", "serialization"]

[dependencies]
displaydoc = { version = "0.1", default-features = false }
vint64 = { version = "0.2", path = "vint64" }

[features]
Expand Down
2 changes: 1 addition & 1 deletion rust/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ without any additional terms or conditions.
[docs-link]: https://docs.rs/veriform/
[license-image]: https://img.shields.io/badge/license-Apache2.0-blue.svg
[license-link]: https://github.com/iqlusioninc/veriform/blob/develop/LICENSE
[msrv-image]: https://img.shields.io/badge/rustc-1.39+-blue.svg
[msrv-image]: https://img.shields.io/badge/rustc-1.40+-blue.svg
[build-image]: https://github.com/iqlusioninc/veriform/workflows/Rust/badge.svg?branch=develop&event=push
[build-link]: https://github.com/iqlusioninc/veriform/actions?query=workflow%3ARust

Expand Down
33 changes: 10 additions & 23 deletions rust/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,48 +1,35 @@
//! Error type

use crate::field::Tag;
use core::fmt::{self, Display};
use displaydoc::Display;

/// Error type
#[derive(Clone, Debug, Eq, PartialEq)]
#[derive(Copy, Clone, Debug, Display, Eq, PartialEq)]
pub enum Error {
/// Malformed data encountered while decoding
/// decode error
Decode,

/// Operation failed or is in a bad state
/// operation failed
Failed,

/// Length is incorrect/insufficient
/// bad length
Length,

/// Field is out-of-order
/// field {tag:?} is out-of-order
Order {
/// Tag of the out-of-order field
/// tag of the out-of-order field
tag: Tag,
},

/// String is not valid UTF-8
/// malformed UTF-8 encountered at byte: {valid_up_to:?}
Utf8 {
/// Byte at which UTF-8 encoding failed
/// byte at which UTF-8 encoding failed
valid_up_to: usize,
},

/// Invalid wire type
/// invalid wire type
WireType,
}

impl Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Error::Decode => write!(f, "decode error"),
Error::Failed => write!(f, "operation failed"),
Error::Length => write!(f, "bad length"),
Error::Order { tag } => write!(f, "out-of-order field: {}", tag),
Error::Utf8 { valid_up_to } => write!(f, "malformed UTF-8 at byte: {}", valid_up_to),
Error::WireType => write!(f, "invalid wire type"),
}
}
}

#[cfg(feature = "std")]
impl std::error::Error for Error {}
2 changes: 1 addition & 1 deletion rust/vint64/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ without any additional terms or conditions.
[docs-link]: https://docs.rs/vint64/
[license-image]: https://img.shields.io/badge/license-Apache2.0-blue.svg
[license-link]: https://github.com/iqlusioninc/veriform/blob/develop/LICENSE
[msrv-image]: https://img.shields.io/badge/rustc-1.39+-blue.svg
[msrv-image]: https://img.shields.io/badge/rustc-1.40+-blue.svg
[safety-image]: https://img.shields.io/badge/unsafe-forbidden-success.svg
[safety-link]: https://github.com/rust-secure-code/safety-dance/
[build-image]: https://github.com/iqlusioninc/veriform/workflows/Rust/badge.svg?branch=develop&event=push
Expand Down