Skip to main content

bitcoin_units/
lib.rs

1// SPDX-License-Identifier: CC0-1.0
2
3//! Rust Bitcoin units library
4//!
5//! This library provides basic types used by the Rust Bitcoin ecosystem.
6
7// Coding conventions.
8#![warn(missing_docs)]
9// Exclude lints we don't think are valuable.
10#![allow(clippy::needless_question_mark)] // https://github.com/rust-bitcoin/rust-bitcoin/pull/2134
11#![allow(clippy::manual_range_contains)] // More readable than clippy's format.
12#![allow(clippy::needless_borrows_for_generic_args)] // https://github.com/rust-lang/rust-clippy/issues/12454
13#![no_std]
14
15// Disable 16-bit support at least for now as we can't guarantee it yet.
16#[cfg(target_pointer_width = "16")]
17compile_error!(
18    "rust-bitcoin currently only supports architectures with pointers wider than 16 bits, let us
19    know if you want 16-bit support. Note that we do NOT guarantee that we will implement it!"
20);
21
22#[cfg(feature = "alloc")]
23extern crate alloc;
24
25#[cfg(feature = "std")]
26extern crate std;
27
28/// A generic serialization/deserialization framework.
29#[cfg(feature = "serde")]
30pub extern crate serde;
31
32#[cfg(test)]
33#[macro_use]
34mod test_macros;
35
36pub mod amount;
37#[cfg(feature = "alloc")]
38pub mod fee_rate;
39#[cfg(feature = "alloc")]
40pub mod locktime;
41#[cfg(feature = "alloc")]
42pub mod parse;
43#[cfg(feature = "alloc")]
44pub mod weight;
45
46pub use self::amount::ParseAmountError;
47#[doc(inline)]
48pub use self::amount::{Amount, SignedAmount};
49#[cfg(feature = "alloc")]
50pub use self::parse::ParseIntError;
51#[cfg(feature = "alloc")]
52#[doc(inline)]
53pub use self::{fee_rate::FeeRate, weight::Weight};
54
55#[rustfmt::skip]
56#[allow(unused_imports)]
57mod prelude {
58    #[cfg(all(feature = "alloc", not(feature = "std")))]
59    pub use alloc::{string::{String, ToString}, vec::Vec, boxed::Box, borrow::{Borrow, BorrowMut, Cow, ToOwned}, slice, rc};
60
61    #[cfg(feature = "std")]
62    pub use std::{string::{String, ToString}, vec::Vec, boxed::Box, borrow::{Borrow, BorrowMut, Cow, ToOwned}, rc};
63}