use serde_json::Value;
use crate::error::VldError;
use crate::schema::VldSchema;
pub struct ZNullable<T: VldSchema> {
inner: T,
}
impl<T: VldSchema> ZNullable<T> {
pub fn new(inner: T) -> Self {
Self { inner }
}
pub fn inner_schema(&self) -> &T {
&self.inner
}
}
impl<T: VldSchema> VldSchema for ZNullable<T> {
type Output = Option<T::Output>;
fn parse_value(&self, value: &Value) -> Result<Option<T::Output>, VldError> {
if value.is_null() {
return Ok(None);
}
self.inner.parse_value(value).map(Some)
}
}