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
34
35
36
37
38
//! base module document
//!

pub mod crypto;
pub mod lru;
mod refcnt;
mod time;
pub mod utils;
mod version;

pub use self::refcnt::RefCnt;
pub use self::time::Time;
pub use self::version::Version;

use std::sync::{Arc, Once, RwLock, ONCE_INIT};

use env_logger;

static INIT: Once = ONCE_INIT;

/// Initialise Zbox environment.
///
/// This function should be called before any other functions provided by Zbox.
/// This function can be called more than one time.
pub fn init_env() {
    // only call the initialisation code once globally
    INIT.call_once(|| {
        env_logger::try_init().ok();
        crypto::Crypto::init().expect("Initialise crypto failed");
    });
}

/// Wrap type into reference type Arc<RwLock<T>>
pub trait IntoRef: Sized {
    fn into_ref(self) -> Arc<RwLock<Self>> {
        Arc::new(RwLock::new(self))
    }
}