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