Files
wasmtime/src/helpers.rs
2019-09-09 11:26:06 +02:00

11 lines
370 B
Rust

use crate::{Error, Result};
use std::convert::TryInto;
use std::time::{SystemTime, UNIX_EPOCH};
pub(crate) fn systemtime_to_timestamp(st: SystemTime) -> Result<u64> {
st.duration_since(UNIX_EPOCH)
.map_err(|_| Error::EINVAL)? // date earlier than UNIX_EPOCH
.as_nanos()
.try_into()
.map_err(Into::into) // u128 doesn't fit into u64
}