Skip to main content

graphrecords_query/capabilities/numeric/
floor.rs

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