mail_core_ng/
utils.rs

1//! Utilities.
2//!
3//! Contains everything which doesn't has a better place
4//! to be put in.
5use std::marker::Send;
6use std::fmt::Debug;
7
8use chrono;
9use futures::Future;
10
11
12/// Type alias for an boxed future which is Send + 'static.
13pub type SendBoxFuture<I, E> = Box<Future<Item=I, Error=E> + Send + 'static>;
14
15/// Returns the current data time.
16pub fn now() -> chrono::DateTime<chrono::Utc> {
17    chrono::Utc::now()
18}
19
20/// Trait to allow const `bool` values in generics.
21pub trait ConstSwitch: Debug + Copy + Send + Sync + 'static {
22    const ENABLED: bool;
23}
24
25/// Struct implementing `ConstSwitch` with `ENABLED = true`.
26#[derive(Debug, Copy, Clone)]
27pub struct Enabled;
28impl ConstSwitch for Enabled { const ENABLED: bool = true; }
29/// Struct implementing `ConstSwitch` with `ENABLED = false`.
30#[derive(Debug, Copy, Clone)]
31pub struct Disabled;
32impl ConstSwitch for Disabled { const ENABLED: bool = false; }
33