From 7a1bc13e8880afc7d94dcb16096559a405f25c8c Mon Sep 17 00:00:00 2001 From: Sarah Shader Date: Wed, 30 Oct 2024 17:32:43 -0400 Subject: [PATCH] Remove a couple clones around deserializing validators (#31219) * GitOrigin-RevId: dd27331ae5f5a70694a1588777367e07eab554d4 --- crates/common/src/schemas/json.rs | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/crates/common/src/schemas/json.rs b/crates/common/src/schemas/json.rs index 34a8319c..caa943c9 100644 --- a/crates/common/src/schemas/json.rs +++ b/crates/common/src/schemas/json.rs @@ -480,7 +480,7 @@ impl TryFrom for DocumentSchema { fn try_from(v: JsonValue) -> Result { let schema_type: Validator = v.try_into()?; - match schema_type.clone() { + match schema_type { Validator::Any => Ok(DocumentSchema::Any), Validator::Union(value) => { let schemas: Vec<_> = value @@ -491,9 +491,7 @@ impl TryFrom for DocumentSchema { // once data has been migrated Ok(object_schema.filter_system_fields()) } else { - Err(anyhow::anyhow!(invalid_top_level_type_in_schema( - &schema_type - ))) + Err(anyhow::anyhow!(invalid_top_level_type_in_schema(&s))) } }) .collect::>()?; @@ -757,15 +755,15 @@ impl TryFrom for ObjectValidator { type Error = anyhow::Error; fn try_from(value: JsonValue) -> Result { - let value = value - .as_object() - .ok_or_else(|| anyhow::anyhow!("Object must be an object"))?; + let JsonValue::Object(value) = value else { + anyhow::bail!("Object must be an object"); + }; let schema = ObjectValidator( value .into_iter() .map(|(k, v)| { let field_name = k.parse::()?; - let field_value = FieldValidator::try_from(v.clone()).map_err(|e| { + let field_value = FieldValidator::try_from(v).map_err(|e| { e.wrap_error_message(|msg| { format!("Invalid validator for key `{field_name}`: {msg}") })