From b5d0fdce115c69dedea2c2112f9e15dc18d5dd78 Mon Sep 17 00:00:00 2001 From: "Heinz N. Gies" Date: Tue, 9 Jul 2024 20:31:42 +0200 Subject: [PATCH] Seperate array and string traits Signed-off-by: Heinz N. Gies --- Cargo.toml | 2 +- src/value/borrowed.rs | 24 ++++++++++++++++-------- src/value/lazy/trait_impls.rs | 13 +++++++------ src/value/owned.rs | 22 ++++++++++++++-------- src/value/tape/trait_impls.rs | 9 +++++---- 5 files changed, 43 insertions(+), 27 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 545842d1..b0fa2ae2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,7 +20,7 @@ simdutf8 = { version = "0.1.4", features = ["public_imp", "aarch64_neon"] } lexical-core = { version = "0.8", features = ["format"] } beef = { version = "0.5", optional = true } halfbrown = "0.2" -value-trait = { version = "0.8" } +value-trait = { version = "0.9" } # ahash known key once_cell = { version = "1.17", optional = true } ahash = { version = "0.8", optional = true } diff --git a/src/value/borrowed.rs b/src/value/borrowed.rs index df951366..b4313663 100644 --- a/src/value/borrowed.rs +++ b/src/value/borrowed.rs @@ -177,9 +177,8 @@ impl<'value> ValueBuilder<'value> for Value<'value> { } } -impl<'value> ValueAsMutContainer for Value<'value> { +impl<'value> ValueAsMutArray for Value<'value> { type Array = Array<'value>; - type Object = Object<'value>; #[cfg_attr(not(feature = "no-inline"), inline)] #[must_use] fn as_array_mut(&mut self) -> Option<&mut Vec>> { @@ -188,6 +187,9 @@ impl<'value> ValueAsMutContainer for Value<'value> { _ => None, } } +} +impl<'value> ValueAsMutObject for Value<'value> { + type Object = Object<'value>; /// Get mutable access to a map. /// /// ```rust @@ -287,9 +289,8 @@ impl<'value> ValueAsScalar for Value<'value> { } } } -impl<'value> ValueAsContainer for Value<'value> { +impl<'value> ValueAsArray for Value<'value> { type Array = Array<'value>; - type Object = Object<'value>; #[cfg_attr(not(feature = "no-inline"), inline)] #[must_use] @@ -299,6 +300,10 @@ impl<'value> ValueAsContainer for Value<'value> { _ => None, } } +} + +impl<'value> ValueAsObject for Value<'value> { + type Object = Object<'value>; #[cfg_attr(not(feature = "no-inline"), inline)] #[must_use] @@ -321,18 +326,21 @@ impl<'value> ValueIntoString for Value<'value> { } } -impl<'value> ValueIntoContainer for Value<'value> { +impl<'value> ValueIntoArray for Value<'value> { type Array = Array<'value>; - type Object = Object<'value>; - fn into_array(self) -> Option<::Array> { + fn into_array(self) -> Option<::Array> { match self { Self::Array(a) => Some(a), _ => None, } } +} + +impl<'value> ValueIntoObject for Value<'value> { + type Object = Object<'value>; - fn into_object(self) -> Option<::Object> { + fn into_object(self) -> Option<::Object> { match self { Self::Object(a) => Some(*a), _ => None, diff --git a/src/value/lazy/trait_impls.rs b/src/value/lazy/trait_impls.rs index f20c0dba..39ec3885 100644 --- a/src/value/lazy/trait_impls.rs +++ b/src/value/lazy/trait_impls.rs @@ -6,12 +6,11 @@ use std::{ use value_trait::{ base::{ - TypedValue, ValueAsContainer, ValueAsMutContainer, ValueAsScalar, ValueIntoString, Writable, + TypedValue, ValueAsArray as _, ValueAsMutArray, ValueAsMutObject, ValueAsObject as _, + ValueAsScalar, ValueIntoString, Writable, }, derived::{ - ValueArrayTryAccess, ValueObjectAccessAsContainer, ValueObjectAccessAsScalar, - ValueObjectAccessTryAsContainer, ValueObjectAccessTryAsScalar, ValueObjectTryAccess, - ValueTryAsScalar, + ValueArrayTryAccess, ValueObjectAccessAsArray as _, ValueObjectAccessAsObject as _, ValueObjectAccessAsScalar, ValueObjectAccessTryAsArray as _, ValueObjectAccessTryAsObject as _, ValueObjectAccessTryAsScalar, ValueObjectTryAccess, ValueTryAsScalar }, TryTypeError, ValueBuilder, ValueType, }; @@ -271,14 +270,16 @@ where } } -impl<'tape, 'input> ValueAsMutContainer for Value<'tape, 'input> { +impl<'tape, 'input> ValueAsMutArray for Value<'tape, 'input> { type Array = Vec>; - type Object = super::borrowed::Object<'input>; #[cfg_attr(not(feature = "no-inline"), inline)] #[must_use] fn as_array_mut(&mut self) -> Option<&mut Vec>> { self.as_mut().as_array_mut() } +} +impl<'tape, 'input> ValueAsMutObject for Value<'tape, 'input> { + type Object = super::borrowed::Object<'input>; #[cfg_attr(not(feature = "no-inline"), inline)] #[must_use] fn as_object_mut(&mut self) -> Option<&mut super::borrowed::Object<'input>> { diff --git a/src/value/owned.rs b/src/value/owned.rs index 04db1000..bfd3c86b 100644 --- a/src/value/owned.rs +++ b/src/value/owned.rs @@ -113,9 +113,8 @@ impl<'input> ValueBuilder<'input> for Value { } } -impl ValueAsMutContainer for Value { +impl ValueAsMutArray for Value { type Array = Vec; - type Object = Object; #[cfg_attr(not(feature = "no-inline"), inline)] #[must_use] fn as_array_mut(&mut self) -> Option<&mut Vec> { @@ -124,6 +123,9 @@ impl ValueAsMutContainer for Value { _ => None, } } +} +impl ValueAsMutObject for Value { + type Object = Object; #[cfg_attr(not(feature = "no-inline"), inline)] #[must_use] fn as_object_mut(&mut self) -> Option<&mut Object> { @@ -203,9 +205,8 @@ impl ValueAsScalar for Value { } } } -impl ValueAsContainer for Value { +impl ValueAsArray for Value { type Array = Vec; - type Object = Object; #[cfg_attr(not(feature = "no-inline"), inline)] #[must_use] fn as_array(&self) -> Option<&Vec> { @@ -214,6 +215,9 @@ impl ValueAsContainer for Value { _ => None, } } +} +impl ValueAsObject for Value { + type Object = Object; #[cfg_attr(not(feature = "no-inline"), inline)] #[must_use] @@ -235,18 +239,20 @@ impl ValueIntoString for Value { } } } -impl ValueIntoContainer for Value { +impl ValueIntoArray for Value { type Array = Vec; - type Object = Object; - fn into_array(self) -> Option<::Array> { + fn into_array(self) -> Option<::Array> { match self { Self::Array(a) => Some(a), _ => None, } } +} +impl ValueIntoObject for Value { + type Object = Object; - fn into_object(self) -> Option<::Object> { + fn into_object(self) -> Option<::Object> { match self { Self::Object(a) => Some(*a), _ => None, diff --git a/src/value/tape/trait_impls.rs b/src/value/tape/trait_impls.rs index 02b69593..c9621451 100644 --- a/src/value/tape/trait_impls.rs +++ b/src/value/tape/trait_impls.rs @@ -5,7 +5,7 @@ use std::{ }; use value_trait::{ - base::{TypedValue, ValueAsScalar, ValueIntoContainer, ValueIntoString, Writable}, + base::{TypedValue, ValueAsScalar, ValueIntoArray, ValueIntoObject, ValueIntoString, Writable}, derived::{ ValueObjectAccessAsScalar, ValueObjectAccessTryAsScalar, ValueTryAsScalar, ValueTryIntoString, @@ -92,9 +92,8 @@ impl<'tape, 'input> ValueIntoString for Value<'tape, 'input> { } } -impl<'tape, 'input> ValueIntoContainer for Value<'tape, 'input> { +impl<'tape, 'input> ValueIntoArray for Value<'tape, 'input> { type Array = Array<'tape, 'input>; - type Object = Object<'tape, 'input>; #[must_use] fn into_array(self) -> Option { if let Some(Node::Array { count, .. }) = self.0.first() { @@ -105,7 +104,9 @@ impl<'tape, 'input> ValueIntoContainer for Value<'tape, 'input> { None } } - +} +impl<'tape, 'input> ValueIntoObject for Value<'tape, 'input> { + type Object = Object<'tape, 'input>; #[must_use] fn into_object(self) -> Option { if let Some(Node::Object { count, .. }) = self.0.first() {