assembly_core/
lib.rs

1//! # Common datastructures and methods
2//!
3//! This module implements core traits for this library
4#![doc(html_logo_url = "https://assembly.lu-dev.net/rust-logo-lu-256.png")]
5#![doc(html_favicon_url = "https://assembly.lu-dev.net/rust-logo-lu-256.png")]
6#![warn(missing_docs)]
7use std::time::Instant;
8
9pub mod borrow;
10pub mod buffer;
11pub mod ldf;
12#[doc(hidden)]
13#[cfg(feature = "nom")]
14pub mod nom_ext;
15#[cfg(feature = "nom")]
16pub mod parser;
17#[cfg(feature = "nom")]
18pub mod reader;
19pub mod types;
20
21#[doc(hidden)]
22#[cfg(feature = "nom")]
23pub extern crate nom;
24#[doc(hidden)]
25pub use displaydoc;
26
27/// Run the function `run` and print the how much time the execution took.
28pub fn time<F, E>(run: F) -> Result<(), E>
29where
30    F: FnOnce() -> Result<(), E>,
31{
32    let start = Instant::now();
33    let res = run();
34    let duration = start.elapsed();
35
36    println!(
37        "{} in {}.{}s",
38        if res.is_ok() { "Finished" } else { "Failed" },
39        duration.as_secs(),
40        duration.subsec_millis(),
41    );
42
43    res
44}