bitcoin_primitives/
lib.rs

1// SPDX-License-Identifier: CC0-1.0
2
3//! # Rust Bitcoin - primitive types.
4//!
5//! Primitive data types that are used throughout the [`rust-bitcoin`] ecosystem.
6//!
7//! This crate can be used in a no-std environment but a lot of the functionality requires an
8//! allocator i.e., requires the `alloc` feature to be enabled.
9//!
10//! [`rust-bitcoin`]: <https://github.com/rust-bitcoin>
11
12#![cfg_attr(all(not(test), not(feature = "std")), no_std)]
13// Experimental features we need.
14#![cfg_attr(docsrs, feature(doc_auto_cfg))]
15// Coding conventions.
16#![warn(missing_docs)]
17#![warn(deprecated_in_future)]
18#![doc(test(attr(warn(unused))))]
19// Exclude lints we don't think are valuable.
20#![allow(clippy::needless_question_mark)] // https://github.com/rust-bitcoin/rust-bitcoin/pull/2134
21#![allow(clippy::manual_range_contains)] // More readable than clippy's format.
22
23#[cfg(feature = "alloc")]
24extern crate alloc;
25
26#[cfg(feature = "std")]
27extern crate std;
28
29#[cfg(feature = "serde")]
30#[macro_use]
31extern crate serde;
32
33pub mod block;
34#[cfg(feature = "alloc")]
35pub mod locktime;
36pub mod merkle_tree;
37pub mod opcodes;
38pub mod pow;
39#[cfg(feature = "alloc")]
40pub mod script;
41pub mod sequence;
42pub mod taproot;
43pub mod transaction;
44#[cfg(feature = "alloc")]
45pub mod witness;
46
47#[doc(inline)]
48pub use units::amount::{self, Amount, SignedAmount};
49#[doc(inline)]
50#[cfg(feature = "alloc")]
51pub use units::{
52    block::{BlockHeight, BlockInterval},
53    fee_rate::{self, FeeRate},
54    weight::{self, Weight},
55};
56#[doc(inline)]
57#[cfg(feature = "alloc")]
58pub use self::{
59    block::{
60        Block, Checked as BlockChecked, Unchecked as BlockUnchecked, Validation as BlockValidation,
61    },
62    locktime::{absolute, relative},
63    transaction::{Transaction, TxIn, TxOut},
64    witness::Witness,
65};
66#[doc(inline)]
67pub use self::{
68    block::{BlockHash, Header as BlockHeader, WitnessCommitment},
69    merkle_tree::{TxMerkleNode, WitnessMerkleNode},
70    pow::CompactTarget,
71    sequence::Sequence,
72    taproot::{TapBranchTag, TapLeafHash, TapLeafTag, TapNodeHash, TapTweakHash, TapTweakTag},
73    transaction::{Txid, Wtxid},
74};
75
76#[rustfmt::skip]
77#[allow(unused_imports)]
78mod prelude {
79    #[cfg(feature = "alloc")]
80    pub use alloc::collections::{BTreeMap, BTreeSet, btree_map, BinaryHeap};
81
82    #[cfg(feature = "alloc")]
83    pub use alloc::{string::{String, ToString}, vec::Vec, boxed::Box, borrow::{Borrow, BorrowMut, Cow, ToOwned}, slice, rc};
84
85    #[cfg(all(feature = "alloc", target_has_atomic = "ptr"))]
86    pub use alloc::sync;
87}