hopr_primitive_types/lib.rs
1//! This crate contains basic types used throughout the entire HOPR codebase.
2//! Types from this crate are not necessarily specific only to HOPR.
3
4/// Contains various size-bounded types
5pub mod bounded;
6/// Enumerates all errors in this crate.
7pub mod errors;
8/// Implements the most primitive types, such as [U256](crate::primitives::U256) or [Address](crate::primitives::Address).
9pub mod primitives;
10/// Contains various implementations of Simple Moving Average.
11pub mod sma;
12/// Defines commonly used traits across the entire code base.
13pub mod traits;
14
15/// Approximately compares two double-precision floats.
16///
17/// This function first tests if the two values relatively differ by at least `epsilon`.
18/// In case they are equal, the second test checks if they differ by at least two representable
19/// units of precision - meaning there can be only two other floats represented in between them.
20/// If both tests pass, the two values are considered (approximately) equal.
21pub fn f64_approx_eq(a: f64, b: f64, epsilon: f64) -> bool {
22 float_cmp::ApproxEq::approx_eq(a, b, (epsilon, 2))
23}
24
25pub mod prelude {
26 pub use super::errors::GeneralError;
27 pub use super::f64_approx_eq;
28 pub use super::primitives::*;
29 pub use super::sma::*;
30 pub use super::traits::*;
31
32 pub use chrono::{DateTime, Utc};
33}