blob: 0ec6ae08c354eab47cce9f3ef212f5f512d1c9d1 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
use std::fmt;
use std::time::{SystemTime, UNIX_EPOCH};
use crate::errors::Error;
use crate::parser::Literal;
use crate::treewalk::interpreter::Value;
pub trait Builtin: fmt::Debug {
fn arity(&self) -> usize;
fn call(&self, args: Vec<Value>) -> Result<Value, Error>;
}
// Builtin to return the current timestamp.
#[derive(Debug)]
pub struct Clock {}
impl Builtin for Clock {
fn arity(&self) -> usize {
0
}
fn call(&self, _args: Vec<Value>) -> Result<Value, Error> {
let now = SystemTime::now().duration_since(UNIX_EPOCH).unwrap();
Ok(Value::Literal(Literal::Number(now.as_secs() as f64)))
}
}
|