chinese-rand

Crates.iochinese-rand
lib.rschinese-rand
version0.2.1
sourcesrc
created_at2024-05-22 15:53:28.484952
updated_at2024-09-22 00:34:24.14877
descriptionRandom generation of data structures in Chinese, using Rust
homepage
repositoryhttps://github.com/giancosta86/chinese-rand
max_upload_size
id1248077
size41,155
Gianluca Costa (giancosta86)

documentation

README

chinese-rand

Random generation of data structures in Chinese, using Rust

Crates.io Version

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_format::{ChineseFormat, Fraction, Variant};
use chinese_rand::*;

fn main() -> GenericResult<()> {
    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, "六分之七");

    #[cfg(feature = "gregorian")]
    {
      // Now setting the random seed just in order to
      //predict the generated values
      fastrand::seed(91);

      let gregorianGenerator = generator.gregorian();

      let delta_time = gregorianGenerator.delta_time(
        gregorian::DeltaTimeParams {
          formal: true
        }
      );

      assert_eq!(
        delta_time.to_chinese(Variant::Simplified),
        "差六分五点"
      );
    }

    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 the data types in the currency module.

  • gregorian: enables the random generation of the data types in the gregorian module, which is dedicated to dates and times.

    Also enables: digit-sequence.

Crates.io

https://crates.io/crates/chinese-rand

Documentation

https://docs.rs/chinese-rand

License

MIT

Commit count: 6

cargo fmt