Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
bitcoinleveldb-status
A small, C++-compatible Status implementation extracted from the Bitcoin Core LevelDB fork.
This crate mirrors the error-handling semantics of LevelDB's C++ Status type as used in Bitcoin Core, while providing an idiomatic Rust API. It is designed to be binary-layout compatible with the original implementation so that Rust code can interoperate cleanly with existing C/C++ LevelDB bindings and on-disk encodings.
Design overview
StatusCode
The StatusCode enum is a direct translation of LevelDB's internal status codes:
``
These codes are encoded as a single byte in the serialized `Status` layout, matching the C++ implementation .
### Status
```rust
Semantics:
Status::ok()orStatus::default()represent success and carry no payload (state: None).- Non-OK statuses hold an encoded byte slice with:
- bytes
[0..4]: little-endianu32length of the message - byte
[4]: theStatusCodeas a rawu8 - bytes
[5..5+len]: UTF-8 error message data (typically from one or twoSlicearguments, concatenated in the C++ implementation)
- bytes
This layout is intentionally low-level so that FFI and on-disk compatibility with Bitcoin's LevelDB fork can be maintained.
The crate provides move- and copy-like constructors/assignments modeled after the C++ interface, but in safe Rust form.
Core API
Construction
use ;
use Slice; // or equivalent, depending on your stack
// OK status
let s_ok = ok;
assert!;
// Error statuses
let msg = from_str;
let st_not_found = not_found;
let extra = from_str;
let st_corrupt = corruption;
Available constructors (all static methods on Status):
Status::ok()Status::not_found(msg: &Slice, msg2: Option<&Slice>)Status::corruption(msg: &Slice, msg2: Option<&Slice>)Status::not_supported(msg: &Slice, msg2: Option<&Slice>)Status::invalid_argument(msg: &Slice, msg2: Option<&Slice>)Status::io_error(msg: &Slice, msg2: Option<&Slice>)
Each method encodes the StatusCode plus the concatenated message into the internal state buffer.
Introspection
if st_not_found.is_not_found
match st_corrupt.code
println!;
Provided predicates:
is_ok(&self) -> boolis_not_found(&self) -> boolis_corruption(&self) -> boolis_io_error(&self) -> boolis_not_supported_error(&self) -> boolis_invalid_argument(&self) -> bool
Plus the low-level code extractor:
code(&self) -> StatusCode
Copy and move semantics
This crate emulates C++ copy/move semantics in a way that is convenient in FFI-heavy or ported codebases:
let original = io_error;
// Copy-construction equivalent
let copy = new_from_other_copy;
assert_eq!;
// Move-construction equivalent
let original_moved = new_from_other;
// `original` is now logically empty (OK) because its state was `take()`n.
// Copy assignment
let mut a = ok;
let b = invalid_argument;
a.assign_from_other_copy;
// Move assignment
let mut c = ok;
let mut d = not_supported;
c.assign_from_other_move;
Internally:
new_from_other(rhs: Status) -> Selftakes ownership ofrhs.stateusingOption::take, leavingrhsasOK.new_from_other_copy(rhs: &Status) -> Selfdeep-copies the internal buffer, preserving C++ copy constructor semantics.assign_from_other_copy(&mut self, rhs: &Status) -> &mut Statusdeep-copies unless both statuses share the same internal pointer.assign_from_other_move(&mut self, rhs: &mut Status) -> &mut Statusdrops any existing data and takesrhs.state.
These helpers are primarily valuable when porting C++ LevelDB/Bitcoin code, where copy/move semantics are explicit in the original source.
String representation
let st = not_found;
assert_eq!;
let ok = ok;
assert_eq!;
Format rules:
OKstatuses stringify to exactly"OK".- Error statuses stringify to a canonical prefix based on
StatusCode:NotFound:Corruption:Not implemented:(forNotSupported)Invalid argument:IO error:
- The encoded UTF-8 message bytes are appended to this prefix.
Logging behavior
Several methods emit log lines through the log facade (or an equivalent logging backend), e.g.:
Status::default()logs when constructing an OK status.Drop for Statuslogs whether an OK or non-OK status is being dropped.- Copy/move helpers log invocation, and move-assign logs when dropping old state.
code()logs a warning if it encounters an unknown numeric code.
For deterministic behavior in production, configure a log-compatible backend (such as env_logger, flexi_logger, or a custom implementation) upstream in your application.
Interoperability and use cases
This crate is intended for:
- Bitcoin Core / LevelDB porting: When mechanically translating C++ code using
leveldb::Statusinto Rust, this type allows nearly one-to-one structural translation, preserving behavior and string formats. - FFI boundaries: When Rust code must interface with existing C/C++ LevelDB implementations that expect the binary layout of the original
Status. The internal[u8]layout is kept as a simple, contiguous representation compatible with C. - Deterministic error semantics: Bitcoin and similar consensus systems often depend on extremely stable error texts and classifications. Matching the C++ implementation minimizes divergence.
If you are building a purely idiomatic Rust system, prefer using Result<T, E> with a structured error type instead. Status is particularly valuable where compatibility and fidelity to legacy behavior matter more than typical Rust ergonomics.
Example: wrapping a LevelDB-like operation
use Status;
use Slice;
Feature expectations
While the exact public API may evolve, this crate is conceptually constrained by the needs of the Bitcoin/LevelDB ecosystem:
- Preserve binary compatibility with C++ LevelDB
Statusencoding. - Provide predicates for all relevant error classes.
- Emit consistent, stable string representations.
- Offer copy/move helpers for mechanical porting of existing C++ code.
If you require additional predicates or status codes, consider whether they exist in the upstream C++ implementation before extending the API, in order to avoid semantic drift.
License and contribution
- License: MIT (matching the broader
bitcoin-rsrepository license). - Repository: https://github.com/klebs6/bitcoin-rs
This crate lives inside a larger ecosystem of Bitcoin-related Rust libraries. Please submit issues and pull requests to that repository, referencing bitcoinleveldb-status explicitly in your description.
By contributing, you agree to license your contributions under the MIT license of the project.