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