Fix no_std build.
This commit is contained in:
@@ -8,64 +8,63 @@ use crate::parser::INT;
|
||||
use crate::result::EvalAltResult;
|
||||
use crate::token::Position;
|
||||
|
||||
#[cfg(not(feature = "no_std"))]
|
||||
use crate::stdlib::time::Instant;
|
||||
|
||||
#[cfg(not(feature = "no_std"))]
|
||||
def_package!(crate:BasicTimePackage:"Basic timing utilities.", lib, {
|
||||
#[cfg(not(feature = "no_std"))]
|
||||
{
|
||||
// Register date/time functions
|
||||
reg_none(lib, "timestamp", || Instant::now(), map);
|
||||
// Register date/time functions
|
||||
reg_none(lib, "timestamp", || Instant::now(), map);
|
||||
|
||||
reg_binary(
|
||||
lib,
|
||||
"-",
|
||||
|ts1: Instant, ts2: Instant| {
|
||||
if ts2 > ts1 {
|
||||
#[cfg(not(feature = "no_float"))]
|
||||
return Ok(-(ts2 - ts1).as_secs_f64());
|
||||
reg_binary(
|
||||
lib,
|
||||
"-",
|
||||
|ts1: Instant, ts2: Instant| {
|
||||
if ts2 > ts1 {
|
||||
#[cfg(not(feature = "no_float"))]
|
||||
return Ok(-(ts2 - ts1).as_secs_f64());
|
||||
|
||||
#[cfg(feature = "no_float")]
|
||||
#[cfg(feature = "no_float")]
|
||||
{
|
||||
let seconds = (ts2 - ts1).as_secs();
|
||||
|
||||
#[cfg(not(feature = "unchecked"))]
|
||||
{
|
||||
let seconds = (ts2 - ts1).as_secs();
|
||||
|
||||
#[cfg(not(feature = "unchecked"))]
|
||||
{
|
||||
if seconds > (MAX_INT as u64) {
|
||||
return Err(Box::new(EvalAltResult::ErrorArithmetic(
|
||||
format!(
|
||||
"Integer overflow for timestamp duration: {}",
|
||||
-(seconds as i64)
|
||||
),
|
||||
Position::none(),
|
||||
)));
|
||||
}
|
||||
if seconds > (MAX_INT as u64) {
|
||||
return Err(Box::new(EvalAltResult::ErrorArithmetic(
|
||||
format!(
|
||||
"Integer overflow for timestamp duration: {}",
|
||||
-(seconds as i64)
|
||||
),
|
||||
Position::none(),
|
||||
)));
|
||||
}
|
||||
return Ok(-(seconds as INT));
|
||||
}
|
||||
} else {
|
||||
#[cfg(not(feature = "no_float"))]
|
||||
return Ok((ts1 - ts2).as_secs_f64());
|
||||
|
||||
#[cfg(feature = "no_float")]
|
||||
{
|
||||
let seconds = (ts1 - ts2).as_secs();
|
||||
|
||||
#[cfg(not(feature = "unchecked"))]
|
||||
{
|
||||
if seconds > (MAX_INT as u64) {
|
||||
return Err(Box::new(EvalAltResult::ErrorArithmetic(
|
||||
format!("Integer overflow for timestamp duration: {}", seconds),
|
||||
Position::none(),
|
||||
)));
|
||||
}
|
||||
}
|
||||
return Ok(seconds as INT);
|
||||
}
|
||||
return Ok(-(seconds as INT));
|
||||
}
|
||||
},
|
||||
result,
|
||||
);
|
||||
}
|
||||
} else {
|
||||
#[cfg(not(feature = "no_float"))]
|
||||
return Ok((ts1 - ts2).as_secs_f64());
|
||||
|
||||
#[cfg(feature = "no_float")]
|
||||
{
|
||||
let seconds = (ts1 - ts2).as_secs();
|
||||
|
||||
#[cfg(not(feature = "unchecked"))]
|
||||
{
|
||||
if seconds > (MAX_INT as u64) {
|
||||
return Err(Box::new(EvalAltResult::ErrorArithmetic(
|
||||
format!("Integer overflow for timestamp duration: {}", seconds),
|
||||
Position::none(),
|
||||
)));
|
||||
}
|
||||
}
|
||||
return Ok(seconds as INT);
|
||||
}
|
||||
}
|
||||
},
|
||||
result,
|
||||
);
|
||||
|
||||
reg_binary(lib, "<", lt::<Instant>, map);
|
||||
reg_binary(lib, "<=", lte::<Instant>, map);
|
||||
|
Reference in New Issue
Block a user