2021-07-18 13:42:39 +00:00
|
|
|
use bytes::Bytes;
|
|
|
|
|
2021-11-09 10:52:10 +00:00
|
|
|
use crate::{InputValueError, InputValueResult, Scalar, ScalarType, Value};
|
2021-07-18 13:42:39 +00:00
|
|
|
|
2021-11-09 10:52:10 +00:00
|
|
|
/// The `Binary` scalar type represents binary data.
|
|
|
|
#[Scalar(internal)]
|
|
|
|
impl ScalarType for Bytes {
|
|
|
|
fn parse(value: Value) -> InputValueResult<Self> {
|
|
|
|
match value {
|
|
|
|
Value::Binary(data) => Ok(data),
|
|
|
|
_ => Err(InputValueError::expected_type(value)),
|
|
|
|
}
|
2021-07-18 13:42:39 +00:00
|
|
|
}
|
|
|
|
|
2021-11-09 10:52:10 +00:00
|
|
|
fn is_valid(value: &Value) -> bool {
|
|
|
|
matches!(value, Value::Binary(_))
|
2021-07-18 13:42:39 +00:00
|
|
|
}
|
|
|
|
|
2021-11-09 10:52:10 +00:00
|
|
|
fn to_value(&self) -> Value {
|
|
|
|
Value::Binary(self.clone())
|
2021-07-18 13:42:39 +00:00
|
|
|
}
|
|
|
|
}
|