start main data types

duration macro
redo-gragh
Avril 4 years ago
parent 3d2e3a59d1
commit 99e740eb97
Signed by: flanchan
GPG Key ID: 284488987C31F630

@ -0,0 +1,22 @@
//! Datatypes for the program
use super::*;
/// A raw file or directory inode number
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Copy)]
#[repr(transparent)]
pub struct INode(u64);
impl INode
{
/// Create a new `INode` wrapper from any `u64` without checking if it is a real inode.
#[inline] pub const unsafe fn new_unchecked(ino: u64) -> Self
{
Self(ino)
}
/// Convert into raw `u64` inode number.
#[inline] pub const fn into_inner(self) -> u64
{
self.0
}
}

@ -178,12 +178,55 @@ where S: Stream
} }
} }
/// Create a duration with time suffix `h`, `m`, `s`, `ms` or `ns`.
///
/// # Combination
/// These can also be combined.
/// ```
/// #use crate::duration;
/// duration!(1 h, 20 m, 30 s);
/// ```
#[macro_export ]macro_rules! duration
{
(0 $($_any:tt)?) => (::std::time::Duration::from_secs(0));
($dur:literal ms) => (::std::time::Duration::from_millis($dur));
($dur:literal ns) => (::std::time::Duration::from_nanos($dur));
($dur:literal s) => (::std::time::Duration::from_secs($dur));
($dur:literal m) => (::std::time::Duration::from_secs($dur * 60));
($dur:literal h) => (::std::time::Duration::from_secs($dur * 60 * 60));
( $($dur:literal $unit:tt),*)=> {
duration!(0 s) $(
+ duration!($dur $unit)
)*
};
}
#[cfg(test)] #[cfg(test)]
mod tests mod tests
{ {
use super::*; use super::*;
#[test]
fn duration()
{
let dur = duration!(1 h) +
duration!(10 m) +
duration!(1 s) +
duration!(10 ms, 2 ns);
println!("{:?}", dur);
let dur2 = duration!(
1 h,
10 m,
1 s,
10 ms,
2 ns
);
println!("{:?}", dur2);
assert_eq!(dur, dur2);
}
#[tokio::test] #[tokio::test]
async fn stream_gating_with_timeout() async fn stream_gating_with_timeout()
{ {

@ -1,9 +1,13 @@
#![allow(dead_code)]
#[macro_use] extern crate pin_project; #[macro_use] extern crate pin_project;
mod ext; #[macro_use] mod ext;
pub use ext::prelude::*; pub use ext::prelude::*;
mod data;
#[tokio::main] #[tokio::main]
async fn main() { async fn main() {
println!("Hello, world!"); println!("Hello, world!");

Loading…
Cancel
Save