use crate::bools::exhaustive::exhaustive_bools;
use crate::num::conversion::string::options::{FromSciStringOptions, SciSizeOptions, ToSciOptions};
use crate::num::exhaustive::{
exhaustive_negative_signeds, primitive_int_increasing_inclusive_range,
};
use crate::num::logic::traits::NotAssign;
use crate::rounding_modes::exhaustive::exhaustive_rounding_modes;
use crate::rounding_modes::RoundingMode;
use crate::tuples::exhaustive::{exhaustive_triples, lex_pairs, lex_quadruples_from_single};
use alloc::boxed::Box;
pub struct ExhaustiveSciSizeOptions {
i: u64,
even: bool,
}
impl Iterator for ExhaustiveSciSizeOptions {
type Item = SciSizeOptions;
fn next(&mut self) -> Option<SciSizeOptions> {
let out = if self.even {
if self.i == 0 {
SciSizeOptions::Complete
} else {
SciSizeOptions::Precision(self.i)
}
} else {
let i = self.i;
self.i += 1;
SciSizeOptions::Scale(i)
};
self.even.not_assign();
Some(out)
}
}
pub const fn exhaustive_sci_size_options() -> ExhaustiveSciSizeOptions {
ExhaustiveSciSizeOptions { i: 0, even: true }
}
pub struct ExhaustiveToSciOptions(
Box<
dyn Iterator<
Item = (
(u8, SciSizeOptions, i64),
(RoundingMode, (bool, bool, bool, bool)),
),
>,
>,
);
impl Iterator for ExhaustiveToSciOptions {
type Item = ToSciOptions;
fn next(&mut self) -> Option<ToSciOptions> {
let (
(base, size_options, neg_exp_threshold),
(
rounding_mode,
(lowercase, e_lowercase, force_exponent_plus_sign, include_trailing_zeros),
),
) = self.0.next()?;
Some(ToSciOptions {
base,
size_options,
neg_exp_threshold,
rounding_mode,
lowercase,
e_lowercase,
force_exponent_plus_sign,
include_trailing_zeros,
})
}
}
pub fn exhaustive_to_sci_options() -> ExhaustiveToSciOptions {
ExhaustiveToSciOptions(Box::new(lex_pairs(
exhaustive_triples(
primitive_int_increasing_inclusive_range(2, 36),
exhaustive_sci_size_options(),
exhaustive_negative_signeds(),
),
lex_pairs(
exhaustive_rounding_modes(),
lex_quadruples_from_single(exhaustive_bools()),
),
)))
}
pub struct ExhaustiveFromSciStringOptions(Box<dyn Iterator<Item = (u8, RoundingMode)>>);
impl Iterator for ExhaustiveFromSciStringOptions {
type Item = FromSciStringOptions;
fn next(&mut self) -> Option<FromSciStringOptions> {
let (base, rounding_mode) = self.0.next()?;
Some(FromSciStringOptions {
base,
rounding_mode,
})
}
}
pub fn exhaustive_from_sci_string_options() -> ExhaustiveFromSciStringOptions {
ExhaustiveFromSciStringOptions(Box::new(lex_pairs(
primitive_int_increasing_inclusive_range(2, 36),
exhaustive_rounding_modes(),
)))
}