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
39
40
41
42
43
44
45
//! # Common datastructures and methods
//!
//! This module implements core traits for this library
#![warn(missing_docs)]
use std::time::Instant;

pub mod borrow;
pub mod buffer;
pub mod ldf;
#[doc(hidden)]
pub mod nom_ext;
pub mod parser;
pub mod reader;
pub mod types;

#[macro_use]
#[doc(hidden)]
pub extern crate num_derive;
#[doc(hidden)]
pub extern crate nom;
#[doc(hidden)]
pub use byteorder;
#[doc(hidden)]
pub use displaydoc;
#[doc(hidden)]
pub use num_traits;

/// Run the function `run` and print the how much time the execution took.
pub fn time<F, E>(run: F) -> Result<(), E>
where
    F: FnOnce() -> Result<(), E>,
{
    let start = Instant::now();
    let res = run();
    let duration = start.elapsed();

    println!(
        "{} in {}.{}s",
        if res.is_ok() { "Finished" } else { "Failed" },
        duration.as_secs(),
        duration.subsec_millis(),
    );

    res
}