Skip to content

Commit

Permalink
Merge pull request #207 from Alexhuszagh/doc_autocfg
Browse files Browse the repository at this point in the history
Simplify the doc annotations.
  • Loading branch information
Alexhuszagh authored Jan 10, 2025
2 parents 60a85da + 68b1763 commit 85d1e4a
Show file tree
Hide file tree
Showing 37 changed files with 436 additions and 609 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Deprecated `Options::set_*` in our write float API since options should be considered immutable.
- Removed `static_assertions` dependency.
- Migrate to using an external crate for our half-precision floats.
- Simplify feature detection internally to make auto-doc more reliable.

### Fixed

Expand Down
4 changes: 2 additions & 2 deletions extras/benchmark/algorithm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ serde_json = "1.0"
[features]
default = ["std", "integers", "floats", "json"]
std = ["lexical-util/std", "lexical-parse-float/std"]
integers = ["lexical-util/integers"]
floats = ["lexical-util/floats"]
integers = ["lexical-util/parse-integers", "lexical-util/write-integers"]
floats = ["lexical-util/parse-floats", "lexical-util/write-floats"]
json = []

[[bench]]
Expand Down
4 changes: 2 additions & 2 deletions extras/benchmark/parse-float/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ power-of-two = ["lexical-util/power-of-two", "lexical-parse-float/power-of-two"]
format = ["lexical-util/format", "lexical-parse-float/format"]
compact = ["lexical-util/compact", "lexical-parse-float/compact"]
asm = []
integers = ["lexical-util/integers"]
floats = ["lexical-util/floats"]
floats = ["lexical-util/parse-floats"]
integers = [] # needed for feature detection
json = []

[[bench]]
Expand Down
4 changes: 2 additions & 2 deletions extras/benchmark/parse-integer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ radix = ["lexical-util/radix", "lexical-parse-integer/radix"]
power-of-two = ["lexical-util/power-of-two", "lexical-parse-integer/power-of-two"]
format = ["lexical-util/format", "lexical-parse-integer/format"]
compact = ["lexical-util/compact", "lexical-parse-integer/compact"]
integers = ["lexical-util/integers"]
floats = ["lexical-util/floats"]
floats = [] # needed for feature detection
integers = ["lexical-util/parse-integers"]
json = []

[[bench]]
Expand Down
4 changes: 2 additions & 2 deletions extras/benchmark/write-float/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ radix = ["lexical-util/radix", "lexical-write-float/radix"]
power-of-two = ["lexical-util/power-of-two", "lexical-write-float/power-of-two"]
format = ["lexical-util/format", "lexical-write-float/format"]
compact = ["lexical-util/compact", "lexical-write-float/compact"]
integers = ["lexical-util/integers"]
floats = ["lexical-util/floats"]
floats = ["lexical-util/write-floats"]
integers = [] # needed for feature detection
json = []

[[bench]]
Expand Down
4 changes: 2 additions & 2 deletions extras/benchmark/write-integer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ radix = ["lexical-util/radix", "lexical-write-integer/radix"]
power-of-two = ["lexical-util/power-of-two", "lexical-write-integer/power-of-two"]
format = ["lexical-util/format", "lexical-write-integer/format"]
compact = ["lexical-util/compact", "lexical-write-integer/compact"]
integers = ["lexical-util/integers"]
floats = ["lexical-util/floats"]
floats = [] # needed for feature detection
integers = ["lexical-util/write-integers"]
json = []

[[bench]]
Expand Down
12 changes: 4 additions & 8 deletions extras/util/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,10 @@ std = ["lexical-util/std"]
power-of-two = ["lexical-util/power-of-two"]
radix = ["lexical-util/radix"]
format = ["lexical-util/format"]
write-integers = ["lexical-util/write-integers", "write", "integers"]
write-floats = ["lexical-util/write-floats", "write", "floats"]
parse-integers = ["lexical-util/parse-integers", "parse", "integers"]
parse-floats = ["lexical-util/parse-floats", "parse", "floats"]
write-integers = ["lexical-util/write-integers"]
write-floats = ["lexical-util/write-floats"]
parse-integers = ["lexical-util/parse-integers"]
parse-floats = ["lexical-util/parse-floats"]
compact = ["lexical-util/compact"]
f16 = ["lexical-util/f16", "parse-floats", "write-floats"]
lint = ["lexical-util/lint"]
write = ["lexical-util/write"]
parse = ["lexical-util/parse"]
integers = ["lexical-util/integers"]
floats = ["lexical-util/floats"]
2 changes: 1 addition & 1 deletion extras/util/tests/div128_tests.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#![cfg(not(feature = "compact"))]
#![cfg(feature = "write")]
#![cfg(any(feature = "write-floats", feature = "write-integers"))]

mod util;

Expand Down
20 changes: 4 additions & 16 deletions lexical-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,13 @@ std = [
"lexical-parse-float/std"
]
# Add support for writing integers.
write-integers = ["lexical-write-integer", "write", "integers"]
write-integers = ["lexical-write-integer"]
# Add support for writing floats.
write-floats = ["lexical-write-float", "write", "floats"]
write-floats = ["lexical-write-float"]
# Add support for parsing integers.
parse-integers = ["lexical-parse-integer", "parse", "integers"]
parse-integers = ["lexical-parse-integer"]
# Add support for parsing floats.
parse-floats = ["lexical-parse-float", "parse", "floats"]
parse-floats = ["lexical-parse-float"]

# Add support for parsing power-of-two float strings.
power-of-two = [
Expand Down Expand Up @@ -117,18 +117,6 @@ lint = [
"lexical-parse-integer?/lint",
"lexical-parse-float?/lint"
]
# Add support for writing numbers.
# Library users should use `write-integers` and `write-floats` instead.
write = ["lexical-util/write"]
# Add support for parsing numbers.
# Library users should use `parse-integers` and `parse-floats` instead.
parse = ["lexical-util/parse"]
# Add support for conversions to or from integers.
# Library users should use `write-integers` and `parse-integers` instead.
integers = ["lexical-util/integers"]
# Add support for conversions to or from floats.
# Library users should use `write-floats` and `parse-floats` instead.
floats = ["lexical-util/floats"]

# UNSUPPORTED
# -----------
Expand Down
92 changes: 33 additions & 59 deletions lexical-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,14 @@
//!
//! <!-- References -->
#![cfg_attr(
feature = "write",
any(feature = "write-floats", feature = "write-integers"),
doc = "
[`FormattedSize`]: FormattedSize
[`T::FORMATTED_SIZE_DECIMAL`]: FormattedSize::FORMATTED_SIZE_DECIMAL
"
)]
#![cfg_attr(
not(feature = "write"),
not(any(feature = "write-floats", feature = "write-integers")),
doc = "
[`FormattedSize`]: https://docs.rs/lexical-core/latest/lexical_core/trait.FormattedSize.html
[`T::FORMATTED_SIZE_DECIMAL`]: https://docs.rs/lexical-core/latest/lexical_core/trait.FormattedSize.html#associatedconstant.FORMATTED_SIZE_DECIMAL
Expand All @@ -124,9 +124,12 @@
//! [`core-write`]: core::fmt::Display::fmt
//!
//! <!-- Spacer for rustfmt -->
#![cfg_attr(feature = "write", doc = "- [`write`]: Write a number to string.")]
#![cfg_attr(
feature = "parse",
any(feature = "write-floats", feature = "write-integers"),
doc = "- [`write`]: Write a number to string."
)]
#![cfg_attr(
any(feature = "parse-floats", feature = "parse-integers"),
doc = "
- [`parse`]: Parse a number from string validating the complete string is a number.
- [`parse_partial`]: Parse a number from string returning the number and the number
Expand Down Expand Up @@ -167,25 +170,25 @@
//!
//! <!-- Spacer for rustfmt -->
#![cfg_attr(
all(feature = "write", feature = "floats"),
feature = "write-floats",
doc = "[`nan_string`]: WriteFloatOptionsBuilder::nan_string"
)]
#![cfg_attr(
all(not(feature = "write"), feature = "parse", feature = "floats"),
all(not(feature = "write-floats"), feature = "parse-floats"),
doc = "[`nan_string`]: ParseFloatOptionsBuilder::nan_string"
)]
#![cfg_attr(
any(not(feature = "floats"), all(not(feature = "write"), not(feature = "parse"))),
all(not(feature = "write-floats"), not(feature = "parse-floats")),
doc = "[`nan_string`]: https://docs.rs/lexical-core/latest/lexical_core/struct.WriteFloatOptionsBuilder.html#method.nan_string"
)]
//!
//! <!-- Spacer for rustfmt -->
#![cfg_attr(
feature = "write",
any(feature = "write-floats", feature = "write-integers"),
doc = "- [`write_with_options`]: Write a number to string using custom formatting options."
)]
#![cfg_attr(
feature = "parse",
any(feature = "parse-floats", feature = "parse-integers"),
doc = "
- [`parse_with_options`]: Parse a number from string using custom formatting options,
validating the complete string is a number.
Expand Down Expand Up @@ -628,21 +631,21 @@
//!
//! <!-- Spacer for Rustfmt -->
#![cfg_attr(
feature = "write",
any(feature = "write-floats", feature = "write-integers"),
doc = "
[`write`]: crate::write
[`write_with_options`]: crate::write_with_options
"
)]
#![cfg_attr(
not(feature = "write"),
not(any(feature = "write-floats", feature = "write-integers")),
doc = "
[`write`]: https://docs.rs/lexical-core/latest/lexical_core/fn.write.html
[`write_with_options`]: https://docs.rs/lexical-core/latest/lexical_core/fn.write_with_options.html
"
)]
#![cfg_attr(
feature = "parse",
any(feature = "parse-floats", feature = "parse-integers"),
doc = "
[`parse`]: crate::parse
[`parse_partial`]: crate::parse_partial
Expand All @@ -651,7 +654,7 @@
"
)]
#![cfg_attr(
not(feature = "parse"),
not(any(feature = "parse-floats", feature = "parse-integers")),
doc = "
[`parse`]: https://docs.rs/lexical-core/latest/lexical_core/fn.parse.html
[`parse_partial`]: https://docs.rs/lexical-core/latest/lexical_core/fn.parse_partial.html
Expand Down Expand Up @@ -704,26 +707,6 @@
)]
#![cfg_attr(rustfmt, rustfmt_skip)] // reason = "this simplifies our imports"

// Ensure our features are properly enabled. This means no parse without
// parse support, etc.
#[cfg(all(feature = "parse", not(any(feature = "parse-integers", feature = "parse-floats"))))]
compile_error!(
"Do not use the `parse` feature directly. Use `parse-integers` and/or `parse-floats` instead."
);

#[cfg(all(feature = "write", not(any(feature = "write-integers", feature = "write-floats"))))]
compile_error!(
"Do not use the `write` feature directly. Use `write-integers` and/or `write-floats` instead."
);

#[cfg(all(feature = "integers", not(any(feature = "write-integers", feature = "parse-integers"))))]
compile_error!("Do not use the `integers` feature directly. Use `write-integers` and/or `parse-integers` instead.");

#[cfg(all(feature = "floats", not(any(feature = "write-floats", feature = "parse-floats"))))]
compile_error!(
"Do not use the `floats` feature directly. Use `write-floats` and/or `parse-floats` instead."
);

// Re-exports
pub use lexical_util::Error;
pub use lexical_util::result::Result;
Expand All @@ -746,11 +729,10 @@ pub use lexical_util::f16::f16;

// PARSE

#[cfg(feature = "parse")]
#[cfg_attr(docsrs, doc(cfg(any(feature = "parse-floats", feature = "parse-integers"))))]
#[cfg(any(feature = "parse-floats", feature = "parse-integers"))]
pub use lexical_util::options::ParseOptions;

#[cfg(feature = "parse")]
#[cfg(any(feature = "parse-floats", feature = "parse-integers"))]
use lexical_util::{from_lexical, from_lexical_with_options};

#[cfg(feature = "parse-floats")]
Expand Down Expand Up @@ -779,15 +761,13 @@ use lexical_parse_integer::{

// WRITE

#[cfg(feature = "write")]
#[cfg_attr(docsrs, doc(cfg(any(feature = "write-floats", feature = "write-integers"))))]
#[cfg(any(feature = "write-floats", feature = "write-integers"))]
pub use lexical_util::options::WriteOptions;

#[cfg(feature = "write")]
#[cfg(any(feature = "write-floats", feature = "write-integers"))]
use lexical_util::{to_lexical, to_lexical_with_options};

#[cfg(feature = "write")]
#[cfg_attr(docsrs, doc(cfg(any(feature = "write-floats", feature = "write-integers"))))]
#[cfg(any(feature = "write-floats", feature = "write-integers"))]
pub use lexical_util::constants::{FormattedSize, BUFFER_SIZE};

#[cfg(feature = "write-floats")]
Expand All @@ -812,7 +792,7 @@ use lexical_write_integer::{ToLexical as ToInteger, ToLexicalWithOptions as ToIn
// API
// ---

#[cfg(feature = "parse")]
#[cfg(any(feature = "parse-floats", feature = "parse-integers"))]
from_lexical!(
"lexical_core",
1234,
Expand All @@ -821,7 +801,7 @@ from_lexical!(
#[cfg_attr(docsrs, doc(cfg(any(feature = "parse-floats", feature = "parse-integers"))))]
);

#[cfg(feature = "parse")]
#[cfg(any(feature = "parse-floats", feature = "parse-integers"))]
from_lexical_with_options!(
"lexical_core",
1234,
Expand All @@ -831,15 +811,15 @@ from_lexical_with_options!(
#[cfg_attr(docsrs, doc(cfg(any(feature = "parse-floats", feature = "parse-integers"))))]
);

#[cfg(feature = "write")]
#[cfg(any(feature = "write-floats", feature = "write-integers"))]
to_lexical!(
"lexical_core",
1234,
u64,
#[cfg_attr(docsrs, doc(cfg(any(feature = "write-floats", feature = "write-integers"))))]
);

#[cfg(feature = "write")]
#[cfg(any(feature = "write-floats", feature = "write-integers"))]
to_lexical_with_options!(
"lexical_core",
1234,
Expand All @@ -856,7 +836,7 @@ to_lexical_with_options!(
/// * `from_lexical_with_options` - The internal trait that implements
/// `from_lexical`.
/// * `options` - The options type to configure settings.
#[cfg(feature = "parse")]
#[cfg(any(feature = "parse-floats", feature = "parse-integers"))]
macro_rules! from_lexical_impl {
($t:ident, $from:ident, $from_options:ident, $options:ident) => {
impl FromLexical for $t {
Expand Down Expand Up @@ -923,7 +903,7 @@ float_from_lexical! { f32 f64 }
/// * `to_lexical_with_options` - The internal trait that implements
/// `to_lexical`.
/// * `options` - The options type to configure settings.
#[cfg(feature = "write")]
#[cfg(any(feature = "write-floats", feature = "write-integers"))]
macro_rules! to_lexical_impl {
($t:ident, $to:ident, $to_options:ident, $options:ident) => {
impl ToLexical for $t {
Expand Down Expand Up @@ -1014,8 +994,7 @@ float_to_lexical! { f32 f64 }
/// # }
/// ```
#[inline]
#[cfg(feature = "write")]
#[cfg_attr(docsrs, doc(cfg(any(feature = "write-floats", feature = "write-integers"))))]
#[cfg(any(feature = "write-floats", feature = "write-integers"))]
pub fn write<N: ToLexical>(n: N, bytes: &mut [u8]) -> &mut [u8] {
n.to_lexical(bytes)
}
Expand Down Expand Up @@ -1079,8 +1058,7 @@ pub fn write<N: ToLexical>(n: N, bytes: &mut [u8]) -> &mut [u8] {
/// # }
/// ```
#[inline]
#[cfg(feature = "write")]
#[cfg_attr(docsrs, doc(cfg(any(feature = "write-floats", feature = "write-integers"))))]
#[cfg(any(feature = "write-floats", feature = "write-integers"))]
pub fn write_with_options<'a, N: ToLexicalWithOptions, const FORMAT: u128>(
n: N,
bytes: &'a mut [u8],
Expand All @@ -1106,8 +1084,7 @@ pub fn write_with_options<'a, N: ToLexicalWithOptions, const FORMAT: u128>(
/// # }
/// ```
#[inline]
#[cfg(feature = "parse")]
#[cfg_attr(docsrs, doc(cfg(any(feature = "parse-floats", feature = "parse-integers"))))]
#[cfg(any(feature = "parse-floats", feature = "parse-integers"))]
pub fn parse<N: FromLexical>(bytes: &[u8]) -> Result<N> {
N::from_lexical(bytes)
}
Expand All @@ -1130,8 +1107,7 @@ pub fn parse<N: FromLexical>(bytes: &[u8]) -> Result<N> {
/// # }
/// ```
#[inline]
#[cfg(feature = "parse")]
#[cfg_attr(docsrs, doc(cfg(any(feature = "parse-floats", feature = "parse-integers"))))]
#[cfg(any(feature = "parse-floats", feature = "parse-integers"))]
pub fn parse_partial<N: FromLexical>(bytes: &[u8]) -> Result<(N, usize)> {
N::from_lexical_partial(bytes)
}
Expand All @@ -1157,8 +1133,7 @@ pub fn parse_partial<N: FromLexical>(bytes: &[u8]) -> Result<(N, usize)> {
/// # }
/// ```
#[inline]
#[cfg(feature = "parse")]
#[cfg_attr(docsrs, doc(cfg(any(feature = "parse-floats", feature = "parse-integers"))))]
#[cfg(any(feature = "parse-floats", feature = "parse-integers"))]
pub fn parse_with_options<N: FromLexicalWithOptions, const FORMAT: u128>(
bytes: &[u8],
options: &N::Options,
Expand Down Expand Up @@ -1188,8 +1163,7 @@ pub fn parse_with_options<N: FromLexicalWithOptions, const FORMAT: u128>(
/// # }
/// ```
#[inline]
#[cfg(feature = "parse")]
#[cfg_attr(docsrs, doc(cfg(any(feature = "parse-floats", feature = "parse-integers"))))]
#[cfg(any(feature = "parse-floats", feature = "parse-integers"))]
pub fn parse_partial_with_options<N: FromLexicalWithOptions, const FORMAT: u128>(
bytes: &[u8],
options: &N::Options,
Expand Down
Loading

0 comments on commit 85d1e4a

Please sign in to comment.