Skip to content

Commit 202b59f

Browse files
committed
Merge #137: Improve public re-exports
1d4d337 Separate public and private use statements (Tobin C. Harding) Pull request description: 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. ACKs for top commit: clarkmoody: ACK 1d4d337 apoelstra: ACK 1d4d337 Tree-SHA512: bdeeb862ea7e1e91f9dbfcce2beff99aedd0bf8cc916607237dff32e2f20be7cb70ef4235d0a823dfea30bd4bf48e0bafbcfa43e13402c7ddf5aadd7a83b64b1
2 parents 7c3ddff + 1d4d337 commit 202b59f

File tree

2 files changed

+23
-19
lines changed

2 files changed

+23
-19
lines changed

src/lib.rs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -130,35 +130,35 @@ extern crate alloc;
130130
#[cfg(any(test, feature = "std"))]
131131
extern crate core;
132132

133+
mod error;
134+
/// Re-exports the hrp types from [`primitives::hrp`] to make importing ergonomic for the top level APIs.
135+
pub mod hrp;
136+
/// All the primitive types and functionality used in encoding and decoding.
137+
pub mod primitives;
138+
/// API for encoding and decoding segwit addresses.
139+
pub mod segwit;
140+
133141
#[cfg(all(feature = "alloc", not(feature = "std"), not(test)))]
134142
use alloc::{string::String, vec::Vec};
135143
use core::fmt;
136144

137145
use crate::error::write_err;
138-
#[doc(inline)]
139-
pub use crate::primitives::checksum::Checksum;
140146
#[cfg(doc)]
141147
use crate::primitives::decode::CheckedHrpstring;
142148
#[cfg(feature = "alloc")]
143149
use crate::primitives::decode::UncheckedHrpstringError;
144150
#[cfg(feature = "alloc")]
145151
use crate::primitives::decode::{ChecksumError, UncheckedHrpstring};
146-
#[doc(inline)]
147-
pub use crate::primitives::gf32::Fe32;
148-
#[doc(inline)]
149-
pub use crate::primitives::hrp::Hrp;
150-
#[doc(inline)]
151-
pub use crate::primitives::iter::{ByteIterExt, Fe32IterExt};
152-
#[doc(inline)]
153-
pub use crate::primitives::{Bech32, Bech32m, NoChecksum};
154152

155-
mod error;
156-
/// Re-exports the hrp types from [`primitives::hrp`] to make importing ergonomic for the top level APIs.
157-
pub mod hrp;
158-
/// All the primitive types and functionality used in encoding and decoding.
159-
pub mod primitives;
160-
/// API for encoding and decoding segwit addresses.
161-
pub mod segwit;
153+
#[rustfmt::skip] // Keep public re-exports separate.
154+
#[doc(inline)]
155+
pub use {
156+
crate::primitives::checksum::Checksum,
157+
crate::primitives::gf32::Fe32,
158+
crate::primitives::hrp::Hrp,
159+
crate::primitives::iter::{ByteIterExt, Fe32IterExt},
160+
crate::primitives::{Bech32, Bech32m, NoChecksum},
161+
};
162162

163163
/// Decodes a bech32 encoded string.
164164
///

src/segwit.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,14 @@ use crate::primitives::iter::{ByteIterExt, Fe32IterExt};
5353
#[cfg(feature = "alloc")]
5454
use crate::primitives::segwit;
5555
use crate::primitives::segwit::{InvalidWitnessVersionError, WitnessLengthError};
56-
#[doc(inline)]
57-
pub use crate::primitives::segwit::{VERSION_0, VERSION_1};
5856
use crate::primitives::{Bech32, Bech32m};
5957

58+
#[rustfmt::skip] // Keep public re-exports separate.
59+
#[doc(inline)]
60+
pub use {
61+
crate::primitives::segwit::{VERSION_0, VERSION_1},
62+
};
63+
6064
/// Decodes a segwit address.
6165
///
6266
/// # Examples

0 commit comments

Comments
 (0)