hopr_primitive_types/
lib.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
//! This crate contains basic types used throughout the entire HOPR codebase.
//! Types from this crate are not necessarily specific only to HOPR.

/// Contains various size-bounded types
pub mod bounded;
/// Enumerates all errors in this crate.
pub mod errors;
/// Implements the most primitive types, such as [U256](crate::primitives::U256) or [Address](crate::primitives::Address).
pub mod primitives;
/// Contains various implementations of Simple Moving Average.
pub mod sma;
/// Defines commonly used traits across the entire code base.
pub mod traits;

/// Approximately compares two double-precision floats.
///
/// This function first tests if the two values relatively differ by at least `epsilon`.
/// In case they are equal, the second test checks if they differ by at least two representable
/// units of precision - meaning there can be only two other floats represented in between them.
/// If both tests pass, the two values are considered (approximately) equal.
pub fn f64_approx_eq(a: f64, b: f64, epsilon: f64) -> bool {
    float_cmp::ApproxEq::approx_eq(a, b, (epsilon, 2))
}

pub mod prelude {
    pub use super::errors::GeneralError;
    pub use super::f64_approx_eq;
    pub use super::primitives::*;
    pub use super::sma::*;
    pub use super::traits::*;

    pub use chrono::{DateTime, Utc};
}