rust-bitcoin-unsafe-fast/hashes
Tobin C. Harding 10374af75c
Make error types uniform
On our way to v1.0.0 we are defining a standard for our error types,
this includes:

- Uses the following derives (unless not possible, usually because of `io::Error`)

  `#[derive(Debug, Clone, PartialEq, Eq)]`

- Has `non_exhaustive` unless we really know we can commit to not adding
  anything.

Furthermore, we are trying to make the codebase easy to read. Error code
is write-once-read-many (well it should be) so if we make all the error
code super uniform the users can flick to an error and quickly see what
it includes. In an effort to achieve this I have made up a style and
over recent times have change much of the error code to that new style,
this PR audits _all_ error types in the code base and enforces the
style, specifically:

- Is layed out: definition, [impl block], Display impl, error::Error impl, From impls
- `error::Error` impl matches on enum even if it returns `None` for all variants
- Display/Error impls import enum variants locally
- match uses *self and `ref e`
- error::Error variants that return `Some` come first, `None` after

Re: non_exhaustive

To make dev and review easier I have added `non_exhaustive` to _every_
error type. We can then remove it error by error as we see fit. This is
because it takes a bit of thinking to do and review where as this patch
should not take much brain power to review.
2023-10-04 15:15:52 +11:00
..
contrib CI: Pin serde_json for MSRV build 2023-07-12 15:50:18 +10:00
embedded hashes/embedded: Add script dir and README 2023-07-18 10:27:48 +10:00
extended_tests/schemars schemars: Add pinning docs 2023-07-18 10:27:48 +10:00
src Make error types uniform 2023-10-04 15:15:52 +11:00
CHANGELOG.md hashes: Remove duplicate entry 2023-09-07 14:19:01 -04:00
Cargo.toml Remove unused internals dependency 2023-09-22 12:36:00 +10:00
README.md hashes: Remove stale status badge 2023-05-25 14:34:28 +10:00

README.md

Bitcoin Hashes Library

This is a simple, no-dependency library which implements the hash functions needed by Bitcoin. These are SHA1, SHA256, SHA256d, SHA512, and RIPEMD160. As an ancilliary thing, it exposes hexadecimal serialization and deserialization, since these are needed to display hashes anway.

Documentation

Minimum Supported Rust Version (MSRV)

This library should always compile with any combination of features on Rust 1.48.0.

To build with the MSRV you will need to pin serde (if you have either the serde or the schemars feature enabled)

# serde 1.0.157 uses syn 2.0 which requires edition 2021
cargo update -p serde --precise 1.0.156

before building. (And if your code is a library, your downstream users will need to run these commands, and so on.)

Contributions

Contributions are welcome, including additional hash function implementations.

Githooks

To assist devs in catching errors before running CI we provide some githooks. If you do not already have locally configured githooks you can use the ones in this repository by running, in the root directory of the repository:

git config --local core.hooksPath githooks/

Alternatively add symlinks in your .git/hooks directory to any of the githooks we provide.

Running Benchmarks

We use a custom Rust compiler configuration conditional to guard the bench mark code. To run the bench marks use: RUSTFLAGS='--cfg=bench' cargo +nightly bench.