#[allow(unused_macros)]
macro_rules! time_it {
( $label:expr, $ms_threshold:expr, $body:expr ) => {{
use std::time::{SystemTime, Duration};
struct Timer {
start: SystemTime,
}
impl Drop for Timer {
fn drop(&mut self) {
let elapsed = self.start.elapsed();
if elapsed.clone().unwrap_or(Duration::from_millis($ms_threshold))
>= Duration::from_millis($ms_threshold)
{
if $label.len() > 0 {
eprint!("{}:", $label);
}
eprintln!("{}:{}: {:?}", file!(), line!(), elapsed);
}
}
}
let _start = Timer { start: SystemTime::now() };
$body
}};
( $label:expr, $body:expr ) => {
time_it!($label, 0, $body)
};
( $body:expr ) => {
time_it!("", $body)
};
}
#[allow(dead_code)]
pub(crate) trait Sendable : Send {}
#[allow(dead_code)]
pub(crate) trait Syncable : Sync {}
macro_rules! assert_send_and_sync {
( $x:ty where $( $g:ident$( : $a:path )? $(,)?)*) => {
impl<$( $g ),*> crate::macros::Sendable for $x
where $( $g: Send + Sync $( + $a )? ),*
{}
impl<$( $g ),*> crate::macros::Syncable for $x
where $( $g: Send + Sync $( + $a )? ),*
{}
};
( $x:ty where $( $g:ident$( : $a:ident $( + $b:ident )* )? $(,)?)*) => {
impl<$( $g ),*> crate::macros::Sendable for $x
where $( $g: Send + Sync $( + $a $( + $b )* )? ),*
{}
impl<$( $g ),*> crate::macros::Syncable for $x
where $( $g: Send + Sync $( + $a $( + $b )* )? ),*
{}
};
( $x:ty ) => {
impl crate::macros::Sendable for $x {}
impl crate::macros::Syncable for $x {}
};
}