From ea0e9d4c7b9d03c5a6501d527b0c44d0f8d58618 Mon Sep 17 00:00:00 2001 From: Richard Newman Date: Fri, 16 Jun 2017 09:15:29 -0700 Subject: [PATCH] Allow instants to pass through schema validation. (#481) r=fluffyemily * Allow instants to pass through schema validation. * Expand cases in SchemaTypeChecking to catch enum bugs. --- db/src/schema.rs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/db/src/schema.rs b/db/src/schema.rs index bf1d22a5..9c5e27fc 100644 --- a/db/src/schema.rs +++ b/db/src/schema.rs @@ -243,12 +243,25 @@ impl SchemaTypeChecking for Schema { (ValueType::Double, tv @ TypedValue::Double(_)) => Ok(tv), (ValueType::String, tv @ TypedValue::String(_)) => Ok(tv), (ValueType::Uuid, tv @ TypedValue::Uuid(_)) => Ok(tv), + (ValueType::Instant, tv @ TypedValue::Instant(_)) => Ok(tv), (ValueType::Keyword, tv @ TypedValue::Keyword(_)) => Ok(tv), // Ref coerces a little: we interpret some things depending on the schema as a Ref. (ValueType::Ref, TypedValue::Long(x)) => Ok(TypedValue::Ref(x)), (ValueType::Ref, TypedValue::Keyword(ref x)) => self.require_entid(&x).map(|entid| TypedValue::Ref(entid)), + // Otherwise, we have a type mismatch. - (value_type, _) => bail!(ErrorKind::BadEDNValuePair(value.clone(), value_type)), + // Enumerate all of the types here to allow the compiler to help us. + // We don't enumerate all `TypedValue` cases, though: that would multiply this + // collection by 8! + (vt @ ValueType::Boolean, _) | + (vt @ ValueType::Long, _) | + (vt @ ValueType::Double, _) | + (vt @ ValueType::String, _) | + (vt @ ValueType::Uuid, _) | + (vt @ ValueType::Instant, _) | + (vt @ ValueType::Keyword, _) | + (vt @ ValueType::Ref, _) + => bail!(ErrorKind::BadEDNValuePair(value.clone(), vt)), } } }