Skip to content

Commit

Permalink
Separate public and private use statements
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
tcharding committed Oct 10, 2023
1 parent ab96bb9 commit 1d4d337
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 19 deletions.
34 changes: 17 additions & 17 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
///
Expand Down
8 changes: 6 additions & 2 deletions src/segwit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 1d4d337

Please sign in to comment.