Skip to main content

fastsim_core/
lib.rs

1//! Core crate for performing FASTSim simulations.
2//!
3//! # Crate Specific Coding Practices
4//! - `#[non_exhaustive]` macro is invoked to force any downstream crate to use
5//!    the `Init` trait to initialize structs that implement this macro
6//! - `#[fastsim_api]` -- used to expose the struct to python and provides assorted other features related to usability
7
8#![allow(clippy::field_reassign_with_default)]
9// TODO: uncomment when docs are somewhat mature to check for missing docs
10// #![warn(missing_docs)]
11// #![warn(missing_docs_in_private_items)]
12
13//! Crate containing models for second-by-second fuel and energy consumption of simulation
14//! of vehicles
15//! # Feature Flags
16#![doc = document_features::document_features!()]
17
18#[macro_use]
19pub mod macros;
20
21extern crate self as fastsim_core;
22#[macro_use]
23extern crate uom;
24
25pub mod drive_cycle;
26pub mod error;
27pub mod gas_properties;
28pub mod imports;
29pub mod prelude;
30// #[cfg(feature = "pyo3")] -- feature gate provided inside module
31pub mod pyo3;
32pub mod si;
33pub mod simdrive;
34#[cfg(feature = "simdrivelabel")]
35pub mod simdrivelabel;
36pub mod traits;
37pub mod uc;
38pub mod utils;
39pub mod vehicle;
40
41#[cfg(feature = "compat")]
42pub mod compat;
43
44use semver::Version;
45use std::sync::LazyLock;
46
47/// Current version of FASTSim as specified in Cargo.toml
48pub static FASTSIM_VERSION: LazyLock<Version> = LazyLock::new(|| {
49    Version::parse(env!("CARGO_PKG_VERSION"))
50        .expect("CARGO_PKG_VERSION should always be valid semver")
51});
52
53/// Function to provide the current FASTSim version for Serde defaults.
54///
55/// Use with:
56/// `#[serde(default = "crate::current_fastsim_version")]`
57pub(crate) fn current_fastsim_version() -> Version {
58    FASTSIM_VERSION.clone()
59}
60
61/// List enabled features
62#[cfg_attr(feature = "pyo3", imports::pyfunction)]
63pub fn enabled_features() -> Vec<String> {
64    vec![
65        #[cfg(feature = "resources")]
66        "resources".into(),
67        #[cfg(feature = "web")]
68        "web".into(),
69        #[cfg(feature = "serde-default")]
70        "serde-default".into(),
71        #[cfg(feature = "csv")]
72        "csv".into(),
73        #[cfg(feature = "json")]
74        "json".into(),
75        #[cfg(feature = "toml")]
76        "toml".into(),
77        #[cfg(feature = "yaml")]
78        "yaml".into(),
79    ]
80}