Skip to main content

graphrecords_query/capabilities/numeric/
ceil.rs

1use crate::{
2    Failure, IndexValue, QueryResult, Scalar, ValueDomain, error::numeric::NonNumericValue,
3};
4use graphrecords_core::graphrecord::{GraphRecordValue, datatypes::Ceil};
5
6pub trait ValueCeil: ValueDomain {
7    fn ceil<'a>(label: &'static str, value: Self::Value<'a>) -> QueryResult<Self::Value<'a>>;
8}
9
10impl ValueCeil for Scalar {
11    fn ceil<'a>(label: &'static str, value: Self::Value<'a>) -> QueryResult<Self::Value<'a>> {
12        match value {
13            GraphRecordValue::Int(_) | GraphRecordValue::Float(_) => Ok(value.ceil()),
14            value => Err(Failure::new(label, NonNumericValue::new(value))),
15        }
16    }
17}
18
19impl ValueCeil for IndexValue<GraphRecordValue> {
20    fn ceil<'a>(label: &'static str, value: Self::Value<'a>) -> QueryResult<Self::Value<'a>> {
21        match value {
22            GraphRecordValue::Int(_) | GraphRecordValue::Float(_) => Ok(value.ceil()),
23            value => Err(Failure::new(label, NonNumericValue::new(value))),
24        }
25    }
26}