From 1d4d3372552da33848bc9b4aa6a08ae046f13990 Mon Sep 17 00:00:00 2001 From: "Tobin C. Harding" Date: Tue, 10 Oct 2023 14:22:46 +1100 Subject: [PATCH] Separate public and private use statements Improve the public exports in two ways: 1. Inline re-exports into the docs of the module that re-exports them. 2. Separate public and private use statements Recently we discussed a way to separate the public and private import statements to make the code more clear and prevent `rustfmt` joining them all together. Separate public exports using a code block and `#[rustfmt::skip]`. Has the nice advantage of reducing the number of `#[doc(inline)]` attributes also. 1. Modules first, as they are part of the project's structure. 2. Private imports 3. Public re-exports (using `rustfmt::skip` to prevent merge) Use the format ```rust mod xyz; mod abc; use ...; pub use { ..., }; ``` This patch introduces changes to the rendered HTML docs. --- src/lib.rs | 34 +++++++++++++++++----------------- src/segwit.rs | 8 ++++++-- 2 files changed, 23 insertions(+), 19 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 2c96bbdcd..355aeac7e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -130,35 +130,35 @@ extern crate alloc; #[cfg(any(test, feature = "std"))] extern crate core; +mod error; +/// Re-exports the hrp types from [`primitives::hrp`] to make importing ergonomic for the top level APIs. +pub mod hrp; +/// All the primitive types and functionality used in encoding and decoding. +pub mod primitives; +/// API for encoding and decoding segwit addresses. +pub mod segwit; + #[cfg(all(feature = "alloc", not(feature = "std"), not(test)))] use alloc::{string::String, vec::Vec}; use core::fmt; use crate::error::write_err; -#[doc(inline)] -pub use crate::primitives::checksum::Checksum; #[cfg(doc)] use crate::primitives::decode::CheckedHrpstring; #[cfg(feature = "alloc")] use crate::primitives::decode::UncheckedHrpstringError; #[cfg(feature = "alloc")] use crate::primitives::decode::{ChecksumError, UncheckedHrpstring}; -#[doc(inline)] -pub use crate::primitives::gf32::Fe32; -#[doc(inline)] -pub use crate::primitives::hrp::Hrp; -#[doc(inline)] -pub use crate::primitives::iter::{ByteIterExt, Fe32IterExt}; -#[doc(inline)] -pub use crate::primitives::{Bech32, Bech32m, NoChecksum}; -mod error; -/// Re-exports the hrp types from [`primitives::hrp`] to make importing ergonomic for the top level APIs. -pub mod hrp; -/// All the primitive types and functionality used in encoding and decoding. -pub mod primitives; -/// API for encoding and decoding segwit addresses. -pub mod segwit; +#[rustfmt::skip] // Keep public re-exports separate. +#[doc(inline)] +pub use { + crate::primitives::checksum::Checksum, + crate::primitives::gf32::Fe32, + crate::primitives::hrp::Hrp, + crate::primitives::iter::{ByteIterExt, Fe32IterExt}, + crate::primitives::{Bech32, Bech32m, NoChecksum}, +}; /// Decodes a bech32 encoded string. /// diff --git a/src/segwit.rs b/src/segwit.rs index f66451737..db2ff263b 100644 --- a/src/segwit.rs +++ b/src/segwit.rs @@ -53,10 +53,14 @@ use crate::primitives::iter::{ByteIterExt, Fe32IterExt}; #[cfg(feature = "alloc")] use crate::primitives::segwit; use crate::primitives::segwit::{InvalidWitnessVersionError, WitnessLengthError}; -#[doc(inline)] -pub use crate::primitives::segwit::{VERSION_0, VERSION_1}; use crate::primitives::{Bech32, Bech32m}; +#[rustfmt::skip] // Keep public re-exports separate. +#[doc(inline)] +pub use { + crate::primitives::segwit::{VERSION_0, VERSION_1}, +}; + /// Decodes a segwit address. /// /// # Examples