Skip to main content

bitcoin_units/
lib.rs

1// SPDX-License-Identifier: CC0-1.0
2
3//! # Rust Bitcoin Unit Types
4//!
5//! This library provides basic types used by the Rust Bitcoin ecosystem.
6//!
7//! If you are using `rust-bitcoin` then you do not need to access this crate directly. Everything
8//! here is re-exported in `rust-bitcoin` at the same path. Also the same re-exports exist in
9//! `primitives` if you are using that crate instead of `bitcoin`.
10//!
11//! # Examples
12//!
13//! ```
14//! // Exactly the same as `use bitcoin::{amount, Amount}`.
15//! use bitcoin_units::{amount, Amount};
16//!
17//! let _amount = Amount::from_sat(1_000)?;
18//! # Ok::<_, amount::OutOfRangeError>(())
19//! ```
20
21#![no_std]
22// Coding conventions.
23#![warn(missing_docs)]
24#![warn(deprecated_in_future)]
25#![doc(test(attr(warn(unused))))]
26// Extra restriction lints.
27#![warn(clippy::indexing_slicing)] // Avoid implicit panics from indexing/slicing.
28
29#[cfg(feature = "alloc")]
30extern crate alloc;
31#[cfg(feature = "std")]
32extern crate std;
33
34#[cfg(feature = "arbitrary")]
35pub extern crate arbitrary;
36#[cfg(feature = "encoding")]
37pub extern crate encoding;
38#[cfg(feature = "serde")]
39pub extern crate serde;
40
41#[doc(hidden)]
42pub mod _export {
43    /// A re-export of `core::*`.
44    pub mod _core {
45        pub use core::*;
46    }
47}
48
49mod fee;
50mod internal_macros;
51
52pub mod amount;
53pub mod block;
54pub mod fee_rate;
55pub mod locktime;
56pub mod parse_int;
57pub mod pow;
58pub mod result;
59pub mod sequence;
60pub mod time;
61pub mod weight;
62
63#[doc(inline)]
64#[rustfmt::skip]
65pub use self::{
66    amount::{Amount, SignedAmount},
67    block::{BlockHeight, BlockHeightInterval, BlockMtp, BlockMtpInterval},
68    fee_rate::FeeRate,
69    locktime::{absolute, relative},
70    pow::{CompactTarget, Target, Work},
71    result::NumOpResult,
72    sequence::Sequence,
73    time::BlockTime,
74    weight::Weight
75};
76
77// decoder_newtype! macro
78#[cfg(feature = "encoding")]
79include!("../include/decoder_newtype.rs");