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