diff options
Diffstat (limited to 'core/src/utils.rs')
-rw-r--r-- | core/src/utils.rs | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/core/src/utils.rs b/core/src/utils.rs new file mode 100644 index 0000000..ebed85b --- /dev/null +++ b/core/src/utils.rs @@ -0,0 +1,33 @@ +//! Utilities. +//! +//! Contains everything which doesn't has a better place +//! to be put in. +use std::marker::Send; +use std::fmt::Debug; + +use chrono; +use futures::Future; + + +/// Type alias for an boxed future which is Send + 'static. +pub type SendBoxFuture<I, E> = Box<Future<Item=I, Error=E> + Send + 'static>; + +/// Returns the current data time. +pub fn now() -> chrono::DateTime<chrono::Utc> { + chrono::Utc::now() +} + +/// Trait to allow const `bool` values in generics. +pub trait ConstSwitch: Debug + Copy + Send + Sync + 'static { + const ENABLED: bool; +} + +/// Struct implementing `ConstSwitch` with `ENABLED = true`. +#[derive(Debug, Copy, Clone)] +pub struct Enabled; +impl ConstSwitch for Enabled { const ENABLED: bool = true; } +/// Struct implementing `ConstSwitch` with `ENABLED = false`. +#[derive(Debug, Copy, Clone)] +pub struct Disabled; +impl ConstSwitch for Disabled { const ENABLED: bool = false; } + |