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#[doc(hidden)]
38pub mod _export {
39    /// A re-export of `core::*`.
40    pub mod _core {
41        pub use core::*;
42    }
43}
44
45mod fee;
46mod internal_macros;
47
48pub mod amount;
49pub mod block;
50pub mod fee_rate;
51pub mod locktime;
52pub mod parse_int;
53pub mod pow;
54pub mod result;
55pub mod sequence;
56pub mod time;
57pub mod weight;
58
59#[doc(inline)]
60#[rustfmt::skip]
61pub use self::{
62    amount::{Amount, SignedAmount},
63    block::{BlockHeight, BlockHeightInterval, BlockMtp, BlockMtpInterval},
64    fee_rate::FeeRate,
65    locktime::{absolute, relative},
66    pow::CompactTarget,
67    result::NumOpResult,
68    sequence::Sequence,
69    time::BlockTime,
70    weight::Weight
71};
72
73#[deprecated(since = "1.0.0-rc.0", note = "use `BlockHeightInterval` instead")]
74#[doc(hidden)]
75pub type BlockInterval = BlockHeightInterval;