diff --git a/serde_arrow/src/arrow2_impl/api.rs b/serde_arrow/src/arrow2_impl/api.rs index 6127d956..0c2a4aa2 100644 --- a/serde_arrow/src/arrow2_impl/api.rs +++ b/serde_arrow/src/arrow2_impl/api.rs @@ -52,10 +52,7 @@ use crate::{ /// # } /// ``` /// -pub fn to_arrow2(fields: &[ArrowField], items: &T) -> Result>> -where - T: Serialize + ?Sized, -{ +pub fn to_arrow2(fields: &[ArrowField], items: T) -> Result>> { let builder = ArrayBuilder::from_arrow2(fields)?; items .serialize(Serializer::new(builder))? diff --git a/serde_arrow/src/arrow2_impl/schema.rs b/serde_arrow/src/arrow2_impl/schema.rs index a2acc88e..18808774 100644 --- a/serde_arrow/src/arrow2_impl/schema.rs +++ b/serde_arrow/src/arrow2_impl/schema.rs @@ -43,7 +43,7 @@ impl Sealed for Vec {} /// Schema support for `Vec` (*requires one of the /// `arrow2-*` features*) impl SchemaLike for Vec { - fn from_value(value: &T) -> Result { + fn from_value(value: T) -> Result { SerdeArrowSchema::from_value(value)?.try_into() } @@ -51,10 +51,7 @@ impl SchemaLike for Vec { SerdeArrowSchema::from_type::(options)?.try_into() } - fn from_samples( - samples: &T, - options: TracingOptions, - ) -> Result { + fn from_samples(samples: T, options: TracingOptions) -> Result { SerdeArrowSchema::from_samples(samples, options)?.try_into() } } diff --git a/serde_arrow/src/arrow_impl/api.rs b/serde_arrow/src/arrow_impl/api.rs index 92644fa7..cc91c084 100644 --- a/serde_arrow/src/arrow_impl/api.rs +++ b/serde_arrow/src/arrow_impl/api.rs @@ -57,7 +57,7 @@ use super::type_support::fields_from_field_refs; /// # } /// ``` /// -pub fn to_arrow(fields: &[FieldRef], items: &T) -> Result> { +pub fn to_arrow(fields: &[FieldRef], items: T) -> Result> { let builder = ArrayBuilder::from_arrow(fields)?; items .serialize(Serializer::new(builder))? @@ -138,10 +138,7 @@ where /// # Ok(()) /// # } /// ``` -pub fn to_record_batch( - fields: &[FieldRef], - items: &T, -) -> Result { +pub fn to_record_batch(fields: &[FieldRef], items: &T) -> Result { let builder = ArrayBuilder::from_arrow(fields)?; items .serialize(Serializer::new(builder))? diff --git a/serde_arrow/src/arrow_impl/schema.rs b/serde_arrow/src/arrow_impl/schema.rs index 5bf45f3d..a692bad9 100644 --- a/serde_arrow/src/arrow_impl/schema.rs +++ b/serde_arrow/src/arrow_impl/schema.rs @@ -1,5 +1,7 @@ use std::sync::Arc; +use serde::{Deserialize, Serialize}; + use crate::{ _impl::arrow::datatypes::{ DataType as ArrowDataType, Field as ArrowField, FieldRef, TimeUnit as ArrowTimeUnit, @@ -76,18 +78,15 @@ impl Sealed for Vec {} /// Schema support for `Vec` (*requires one of the /// `arrow-*` features*) impl SchemaLike for Vec { - fn from_value(value: &T) -> Result { + fn from_value(value: T) -> Result { SerdeArrowSchema::from_value(value)?.try_into() } - fn from_type<'de, T: serde::Deserialize<'de>>(options: TracingOptions) -> Result { + fn from_type<'de, T: Deserialize<'de>>(options: TracingOptions) -> Result { SerdeArrowSchema::from_type::(options)?.try_into() } - fn from_samples( - samples: &T, - options: TracingOptions, - ) -> Result { + fn from_samples(samples: T, options: TracingOptions) -> Result { SerdeArrowSchema::from_samples(samples, options)?.try_into() } } @@ -97,18 +96,15 @@ impl Sealed for Vec {} /// Schema support for `Vec` (*requires one of the /// `arrow-*` features*) impl SchemaLike for Vec { - fn from_value(value: &T) -> Result { + fn from_value(value: T) -> Result { SerdeArrowSchema::from_value(value)?.try_into() } - fn from_type<'de, T: serde::Deserialize<'de>>(options: TracingOptions) -> Result { + fn from_type<'de, T: Deserialize<'de>>(options: TracingOptions) -> Result { SerdeArrowSchema::from_type::(options)?.try_into() } - fn from_samples( - samples: &T, - options: TracingOptions, - ) -> Result { + fn from_samples(samples: T, options: TracingOptions) -> Result { SerdeArrowSchema::from_samples(samples, options)?.try_into() } } diff --git a/serde_arrow/src/internal/array_builder.rs b/serde_arrow/src/internal/array_builder.rs index 6b07eec8..27ea7958 100644 --- a/serde_arrow/src/internal/array_builder.rs +++ b/serde_arrow/src/internal/array_builder.rs @@ -73,13 +73,13 @@ impl std::fmt::Debug for ArrayBuilder { impl ArrayBuilder { /// Add a single record to the arrays /// - pub fn push(&mut self, item: &T) -> Result<()> { + pub fn push(&mut self, item: T) -> Result<()> { self.builder.push(item) } /// Add multiple records to the arrays /// - pub fn extend(&mut self, items: &T) -> Result<()> { + pub fn extend(&mut self, items: T) -> Result<()> { self.builder.extend(items) } } diff --git a/serde_arrow/src/internal/schema/from_samples/mod.rs b/serde_arrow/src/internal/schema/from_samples/mod.rs index 6914e40d..18ef607e 100644 --- a/serde_arrow/src/internal/schema/from_samples/mod.rs +++ b/serde_arrow/src/internal/schema/from_samples/mod.rs @@ -18,10 +18,7 @@ use super::tracer::{ }; impl Tracer { - pub fn from_samples( - samples: &T, - options: TracingOptions, - ) -> Result { + pub fn from_samples(samples: T, options: TracingOptions) -> Result { let options = options.tracing_mode(TracingMode::FromSamples); let mut tracer = Tracer::new(String::from("$"), String::from("$"), Arc::new(options)); samples.serialize(OuterSequenceSerializer(&mut tracer))?; diff --git a/serde_arrow/src/internal/schema/mod.rs b/serde_arrow/src/internal/schema/mod.rs index 09157a88..b196b7e9 100644 --- a/serde_arrow/src/internal/schema/mod.rs +++ b/serde_arrow/src/internal/schema/mod.rs @@ -133,7 +133,7 @@ pub trait SchemaLike: Sized + Sealed { /// fields, named `"key"` of integer type and named `"value"` of string /// type /// - fn from_value(value: &T) -> Result; + fn from_value(value: T) -> Result; /// Determine the schema from the given record type. See [`TracingOptions`] for customization /// options. @@ -271,7 +271,7 @@ pub trait SchemaLike: Sized + Sealed { /// # #[cfg(not(has_arrow))] /// # fn main() { } /// ``` - fn from_samples(samples: &T, options: TracingOptions) -> Result; + fn from_samples(samples: T, options: TracingOptions) -> Result; } /// A collection of fields as understood by `serde_arrow` @@ -286,7 +286,7 @@ pub struct SerdeArrowSchema { impl Sealed for SerdeArrowSchema {} impl SchemaLike for SerdeArrowSchema { - fn from_value(value: &T) -> Result { + fn from_value(value: T) -> Result { value::transmute(value) } @@ -294,7 +294,7 @@ impl SchemaLike for SerdeArrowSchema { Tracer::from_type::(options)?.to_schema() } - fn from_samples(samples: &T, options: TracingOptions) -> Result { + fn from_samples(samples: T, options: TracingOptions) -> Result { Tracer::from_samples(samples, options)?.to_schema() } } diff --git a/serde_arrow/src/internal/serialization/outer_sequence_builder.rs b/serde_arrow/src/internal/serialization/outer_sequence_builder.rs index f727ef85..58bbf1ba 100644 --- a/serde_arrow/src/internal/serialization/outer_sequence_builder.rs +++ b/serde_arrow/src/internal/serialization/outer_sequence_builder.rs @@ -45,13 +45,13 @@ impl OuterSequenceBuilder { } /// Extend the builder with a sequence of items - pub fn extend(&mut self, value: &T) -> Result<()> { + pub fn extend(&mut self, value: T) -> Result<()> { value.serialize(Mut(self)) } /// Push a single item into the builder - pub fn push(&mut self, value: &T) -> Result<()> { - self.element(value) + pub fn push(&mut self, value: T) -> Result<()> { + self.element(&value) } } diff --git a/serde_arrow/src/internal/utils/value.rs b/serde_arrow/src/internal/utils/value.rs index 2dc7c1b5..68037dfe 100644 --- a/serde_arrow/src/internal/utils/value.rs +++ b/serde_arrow/src/internal/utils/value.rs @@ -82,7 +82,7 @@ impl std::hash::Hash for HashF64 { } } -pub fn transmute(value: &S) -> Result { +pub fn transmute(value: S) -> Result { let value = value.serialize(ValueSerializer)?; T::deserialize(ValueDeserializer::new(&value)) }