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// Exclude lints we don't think are valuable.
27#![allow(clippy::uninlined_format_args)] // Allow `format!("{}", x)` instead of enforcing `format!("{x}")`
28// Extra restriction lints.
29#![warn(clippy::indexing_slicing)] // Avoid implicit panics from indexing/slicing.
30
31#[cfg(feature = "alloc")]
32extern crate alloc;
33
34#[cfg(feature = "std")]
35extern crate std;
36
37#[cfg(feature = "encoding")]
38pub extern crate encoding;
39
40#[cfg(feature = "serde")]
41pub extern crate serde;
42
43#[cfg(feature = "arbitrary")]
44pub extern crate arbitrary;
45
46#[doc(hidden)]
47pub mod _export {
48    /// A re-export of `core::*`.
49    pub mod _core {
50        pub use core::*;
51    }
52}
53
54mod fee;
55mod internal_macros;
56
57pub mod amount;
58pub mod block;
59pub mod fee_rate;
60pub mod locktime;
61pub mod parse_int;
62pub mod pow;
63pub mod result;
64pub mod sequence;
65pub mod time;
66pub mod weight;
67
68#[doc(inline)]
69#[rustfmt::skip]
70pub use self::{
71    amount::{Amount, SignedAmount},
72    block::{BlockHeight, BlockHeightInterval, BlockMtp, BlockMtpInterval},
73    fee_rate::FeeRate,
74    locktime::{absolute, relative},
75    pow::{CompactTarget, Target, Work},
76    result::NumOpResult,
77    sequence::Sequence,
78    time::BlockTime,
79    weight::Weight
80};
81
82#[deprecated(since = "1.0.0-rc.0", note = "use `BlockHeightInterval` instead")]
83#[doc(hidden)]
84pub type BlockInterval = BlockHeightInterval;
85
86// decoder_newtype! macro
87#[cfg(feature = "encoding")]
88include!("../include/decoder_newtype.rs");