Skip to main content

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