diff options
| author | Jan Tuomi <jan@jantuomi.fi> | 2025-02-10 18:17:40 +0200 |
|---|---|---|
| committer | Jan Tuomi <jan@jantuomi.fi> | 2025-02-10 18:17:40 +0200 |
| commit | 591053c55753e00341bd739c00f9ff09ae6e8141 (patch) | |
| tree | debb9a661def6a9e93ad595a8bd44bfdcc2fefb9 /log_db/src/record.rs | |
| parent | eaa04ae170e57b1688bd10936a19fcb91f3409e0 (diff) | |
Remove typechecking
Diffstat (limited to 'log_db/src/record.rs')
| -rw-r--r-- | log_db/src/record.rs | 64 |
1 files changed, 0 insertions, 64 deletions
diff --git a/log_db/src/record.rs b/log_db/src/record.rs index c373897..8108fb5 100644 --- a/log_db/src/record.rs +++ b/log_db/src/record.rs @@ -48,70 +48,6 @@ impl Record { pub fn at(&self, index: usize) -> &Value { &self.values[index] } - - pub fn validate<Field: Eq>(&self, schema: &[(Field, Type)]) -> DBResult<()> { - // If there are more values than schema fields, it's an error. - if self.values.len() > schema.len() { - return Err(DBError::ValidationError(format!( - "Record has more fields ({}) than expected by the schema ({})", - self.values.len(), - schema.len() - ))); - } - - for (i, (_, typ)) in schema.iter().enumerate() { - match self.values.get(i) { - Some(value) => { - if !Self::value_matches_type(value, typ) { - return Err(DBError::ValidationError(format!( - "Record field {} has incorrect type: {:?}, expected {:?}", - i, value, typ.primitive - ))); - } - } - // If the field is missing from the record... - None => { - // ...it's allowed only if the schema says the field is nullable. - if !typ.nullable { - return Err(DBError::ValidationError(format!( - "Record is missing field expected by the schema ({:?}) at index {}", - typ, i - ))); - } - } - } - } - - Ok(()) - } - - fn value_matches_type(value: &Value, typ: &Type) -> bool { - match (value, typ) { - (Value::Null, Type { nullable: true, .. }) => true, - ( - Value::Int(_), - Type { - primitive: PrimitiveType::Int, - .. - }, - ) => true, - ( - Value::String(_), - Type { - primitive: PrimitiveType::String, - .. - }, - ) => true, - ( - Value::Bytes(_), - Type { - primitive: PrimitiveType::Bytes, - .. - }, - ) => true, - _ => false, - } - } } #[cfg(test)] |
