factorion_lib/
lib.rs

1#![doc = include_str!("../README.md")]
2
3use std::collections::HashMap;
4
5use factorion_math as math;
6use rug::Integer;
7pub mod calculation_results;
8pub mod calculation_tasks;
9pub mod comment;
10pub mod locale;
11pub mod parse;
12/// The result of a calculation
13pub use calculation_results::Calculation;
14/// The format prepped for calculation
15pub use calculation_tasks::CalculationJob;
16/// Convenient abstraction for comments with commands
17pub use comment::{Commands, Comment};
18/// The version of rug we use (for convenience)
19pub use factorion_math::rug;
20/// The parser
21pub use parse::parse;
22
23use crate::locale::Locale;
24
25pub mod recommended {
26    pub use crate::calculation_results::recommended::*;
27    pub use crate::calculation_tasks::recommended::*;
28    pub use crate::parse::recommended::*;
29    pub use factorion_math::recommended::FLOAT_PRECISION;
30}
31
32#[derive(Debug, Clone)]
33pub struct Consts<'a> {
34    pub float_precision: u32,
35    pub upper_calculation_limit: Integer,
36    pub upper_approximation_limit: Integer,
37    pub upper_subfactorial_limit: Integer,
38    pub upper_termial_limit: Integer,
39    pub upper_termial_approximation_limit: u32,
40    pub integer_construction_limit: Integer,
41    pub number_decimals_scientific: usize,
42    pub locales: HashMap<String, Locale<'a>>,
43    pub default_locale: String,
44}
45impl Default for Consts<'_> {
46    fn default() -> Self {
47        Consts {
48            float_precision: math::recommended::FLOAT_PRECISION,
49            upper_calculation_limit: calculation_tasks::recommended::UPPER_CALCULATION_LIMIT(),
50            upper_approximation_limit: calculation_tasks::recommended::UPPER_APPROXIMATION_LIMIT(),
51            upper_subfactorial_limit: calculation_tasks::recommended::UPPER_SUBFACTORIAL_LIMIT(),
52            upper_termial_limit: calculation_tasks::recommended::UPPER_TERMIAL_LIMIT(),
53            upper_termial_approximation_limit:
54                calculation_tasks::recommended::UPPER_TERMIAL_APPROXIMATION_LIMIT,
55            integer_construction_limit: parse::recommended::INTEGER_CONSTRUCTION_LIMIT(),
56            number_decimals_scientific:
57                calculation_results::recommended::NUMBER_DECIMALS_SCIENTIFIC,
58            locales: HashMap::from([
59                #[cfg(any(feature = "serde", test))]
60                ("en".to_owned(), locale::get_en()),
61                #[cfg(any(feature = "serde", test))]
62                ("de".to_owned(), locale::get_de()),
63            ]),
64            default_locale: "en".to_owned(),
65        }
66    }
67}