pub struct Duration(pub Duration);
Expand description
A wrapper Duration type which allows conversion to Value::Duration for types using automatic conversion with serde::Serialize.
§Examples
use cel_interpreter::{Context, Duration, Program};
use serde::Serialize;
#[derive(Serialize)]
struct MyStruct {
dur: Duration,
}
let mut context = Context::default();
// MyStruct will be implicitly serialized into the CEL appropriate types
context
.add_variable(
"foo",
MyStruct {
dur: chrono::Duration::hours(2).into(),
},
)
.unwrap();
let program = Program::compile("foo.dur == duration('2h')").unwrap();
let value = program.execute(&context).unwrap();
assert_eq!(value, true.into());
Tuple Fields§
§0: Duration
Trait Implementations§
Source§impl Ord for Duration
impl Ord for Duration
Source§impl PartialOrd for Duration
impl PartialOrd for Duration
impl Copy for Duration
impl Eq for Duration
impl StructuralPartialEq for Duration
Auto Trait Implementations§
impl Freeze for Duration
impl RefUnwindSafe for Duration
impl Send for Duration
impl Sync for Duration
impl Unpin for Duration
impl UnwindSafe for Duration
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more