Expand description
This crate is designed to instantiate random instances of the data structures implementing the ChineseFormat trait, made available by chinese_format.
The core concept is the ChineseFormatGenerator struct, which can be instantiated by passing an object implementing the RawGenerator trait:
use chinese_rand::*;
use chinese_format::{ChineseFormat, Fraction, Variant};
let generator = ChineseFormatGenerator::new(
FastRandGenerator::new()
);
// Now setting the random seed just in order to
//predict the generated values
fastrand::seed(90);
let fraction: Fraction = generator.fraction(
1..=10,
1..=10
)?;
let chinese = fraction.to_chinese(Variant::Simplified);
assert_eq!(chinese, "六分之七");
Ok(())
}§Features
-
fastrand: enables FastRandGenerator, based on fastrand. Enabled by default. -
digit-sequence: enables random generation of data types - like Decimal - based on DigitSequence. -
currency: enables the random generation of data types in the currency module. -
gregorian: enables the random generation of data types in the gregorian module, which is dedicated to dates and times.Also enables:
digit-sequence.
Modules§
- gregorian
- Module supporting the random generation of date/time objects according to the Gregorian calendar.
Structs§
- Chinese
Format Generator - Parametrically generates random instances of the data structures provided by chinese_format.
- Fast
Rand Generator - Implementation of RawGenerator based on fastrand.
- Invalid
Lower Bound - When a lower bound is not acceptable.
- Renminbi
Params - Parameters for the random creation of RenminbiCurrency.
Traits§
- RawGenerator
- Generator of primitive values required by ChineseFormatGenerator.
Type Aliases§
- Generic
Result - The most generic Error-based Result.