Skip to content

Commit

Permalink
Seperate array and string traits
Browse files Browse the repository at this point in the history
Signed-off-by: Heinz N. Gies <[email protected]>
  • Loading branch information
Licenser committed Aug 3, 2024
1 parent 5294c92 commit b5d0fdc
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 27 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
24 changes: 16 additions & 8 deletions src/value/borrowed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Value<'value>>> {
Expand All @@ -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
Expand Down Expand Up @@ -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]
Expand All @@ -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]
Expand All @@ -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<<Self as ValueIntoContainer>::Array> {
fn into_array(self) -> Option<<Self as ValueIntoArray>::Array> {
match self {
Self::Array(a) => Some(a),
_ => None,
}
}
}

impl<'value> ValueIntoObject for Value<'value> {
type Object = Object<'value>;

fn into_object(self) -> Option<<Self as ValueIntoContainer>::Object> {
fn into_object(self) -> Option<<Self as ValueIntoObject>::Object> {
match self {
Self::Object(a) => Some(*a),
_ => None,
Expand Down
13 changes: 7 additions & 6 deletions src/value/lazy/trait_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down Expand Up @@ -271,14 +270,16 @@ where
}
}

impl<'tape, 'input> ValueAsMutContainer for Value<'tape, 'input> {
impl<'tape, 'input> ValueAsMutArray for Value<'tape, 'input> {
type Array = Vec<borrowed::Value<'input>>;
type Object = super::borrowed::Object<'input>;
#[cfg_attr(not(feature = "no-inline"), inline)]
#[must_use]
fn as_array_mut(&mut self) -> Option<&mut Vec<borrowed::Value<'input>>> {
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>> {
Expand Down
22 changes: 14 additions & 8 deletions src/value/owned.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,8 @@ impl<'input> ValueBuilder<'input> for Value {
}
}

impl ValueAsMutContainer for Value {
impl ValueAsMutArray for Value {
type Array = Vec<Self>;
type Object = Object;
#[cfg_attr(not(feature = "no-inline"), inline)]
#[must_use]
fn as_array_mut(&mut self) -> Option<&mut Vec<Self>> {
Expand All @@ -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> {
Expand Down Expand Up @@ -203,9 +205,8 @@ impl ValueAsScalar for Value {
}
}
}
impl ValueAsContainer for Value {
impl ValueAsArray for Value {
type Array = Vec<Self>;
type Object = Object;
#[cfg_attr(not(feature = "no-inline"), inline)]
#[must_use]
fn as_array(&self) -> Option<&Vec<Self>> {
Expand All @@ -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]
Expand All @@ -235,18 +239,20 @@ impl ValueIntoString for Value {
}
}
}
impl ValueIntoContainer for Value {
impl ValueIntoArray for Value {
type Array = Vec<Self>;
type Object = Object;

fn into_array(self) -> Option<<Value as ValueIntoContainer>::Array> {
fn into_array(self) -> Option<<Value as ValueIntoArray>::Array> {
match self {
Self::Array(a) => Some(a),
_ => None,
}
}
}
impl ValueIntoObject for Value {
type Object = Object;

fn into_object(self) -> Option<<Value as ValueIntoContainer>::Object> {
fn into_object(self) -> Option<<Value as ValueIntoObject>::Object> {
match self {
Self::Object(a) => Some(*a),
_ => None,
Expand Down
9 changes: 5 additions & 4 deletions src/value/tape/trait_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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<Self::Array> {
if let Some(Node::Array { count, .. }) = self.0.first() {
Expand All @@ -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<Self::Object> {
if let Some(Node::Object { count, .. }) = self.0.first() {
Expand Down

0 comments on commit b5d0fdc

Please sign in to comment.