Skip to content

Commit

Permalink
Merge pull request #233 from chmp/feature/remove-refs-and-sized
Browse files Browse the repository at this point in the history
Remove refs and sized
  • Loading branch information
chmp committed Sep 16, 2024
2 parents 23b8cb6 + b79f86d commit eae1992
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 40 deletions.
5 changes: 1 addition & 4 deletions serde_arrow/src/arrow2_impl/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,7 @@ use crate::{
/// # }
/// ```
///
pub fn to_arrow2<T>(fields: &[ArrowField], items: &T) -> Result<Vec<Box<dyn Array>>>
where
T: Serialize + ?Sized,
{
pub fn to_arrow2<T: Serialize>(fields: &[ArrowField], items: T) -> Result<Vec<Box<dyn Array>>> {
let builder = ArrayBuilder::from_arrow2(fields)?;
items
.serialize(Serializer::new(builder))?
Expand Down
7 changes: 2 additions & 5 deletions serde_arrow/src/arrow2_impl/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,15 @@ impl Sealed for Vec<ArrowField> {}
/// Schema support for `Vec<arrow2::datatype::Field>` (*requires one of the
/// `arrow2-*` features*)
impl SchemaLike for Vec<ArrowField> {
fn from_value<T: serde::Serialize + ?Sized>(value: &T) -> Result<Self> {
fn from_value<T: serde::Serialize>(value: T) -> Result<Self> {
SerdeArrowSchema::from_value(value)?.try_into()
}

fn from_type<'de, T: serde::Deserialize<'de>>(options: TracingOptions) -> Result<Self> {
SerdeArrowSchema::from_type::<T>(options)?.try_into()
}

fn from_samples<T: serde::Serialize + ?Sized>(
samples: &T,
options: TracingOptions,
) -> Result<Self> {
fn from_samples<T: serde::Serialize>(samples: T, options: TracingOptions) -> Result<Self> {
SerdeArrowSchema::from_samples(samples, options)?.try_into()
}
}
Expand Down
7 changes: 2 additions & 5 deletions serde_arrow/src/arrow_impl/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ use super::type_support::fields_from_field_refs;
/// # }
/// ```
///
pub fn to_arrow<T: Serialize + ?Sized>(fields: &[FieldRef], items: &T) -> Result<Vec<ArrayRef>> {
pub fn to_arrow<T: Serialize>(fields: &[FieldRef], items: T) -> Result<Vec<ArrayRef>> {
let builder = ArrayBuilder::from_arrow(fields)?;
items
.serialize(Serializer::new(builder))?
Expand Down Expand Up @@ -138,10 +138,7 @@ where
/// # Ok(())
/// # }
/// ```
pub fn to_record_batch<T: Serialize + ?Sized>(
fields: &[FieldRef],
items: &T,
) -> Result<RecordBatch> {
pub fn to_record_batch<T: Serialize>(fields: &[FieldRef], items: &T) -> Result<RecordBatch> {
let builder = ArrayBuilder::from_arrow(fields)?;
items
.serialize(Serializer::new(builder))?
Expand Down
20 changes: 8 additions & 12 deletions serde_arrow/src/arrow_impl/schema.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -76,18 +78,15 @@ impl Sealed for Vec<ArrowField> {}
/// Schema support for `Vec<arrow::datatype::Field>` (*requires one of the
/// `arrow-*` features*)
impl SchemaLike for Vec<ArrowField> {
fn from_value<T: serde::Serialize + ?Sized>(value: &T) -> Result<Self> {
fn from_value<T: Serialize>(value: T) -> Result<Self> {
SerdeArrowSchema::from_value(value)?.try_into()
}

fn from_type<'de, T: serde::Deserialize<'de>>(options: TracingOptions) -> Result<Self> {
fn from_type<'de, T: Deserialize<'de>>(options: TracingOptions) -> Result<Self> {
SerdeArrowSchema::from_type::<T>(options)?.try_into()
}

fn from_samples<T: serde::Serialize + ?Sized>(
samples: &T,
options: TracingOptions,
) -> Result<Self> {
fn from_samples<T: Serialize>(samples: T, options: TracingOptions) -> Result<Self> {
SerdeArrowSchema::from_samples(samples, options)?.try_into()
}
}
Expand All @@ -97,18 +96,15 @@ impl Sealed for Vec<FieldRef> {}
/// Schema support for `Vec<arrow::datatype::FieldRef>` (*requires one of the
/// `arrow-*` features*)
impl SchemaLike for Vec<FieldRef> {
fn from_value<T: serde::Serialize + ?Sized>(value: &T) -> Result<Self> {
fn from_value<T: Serialize>(value: T) -> Result<Self> {
SerdeArrowSchema::from_value(value)?.try_into()
}

fn from_type<'de, T: serde::Deserialize<'de>>(options: TracingOptions) -> Result<Self> {
fn from_type<'de, T: Deserialize<'de>>(options: TracingOptions) -> Result<Self> {
SerdeArrowSchema::from_type::<T>(options)?.try_into()
}

fn from_samples<T: serde::Serialize + ?Sized>(
samples: &T,
options: TracingOptions,
) -> Result<Self> {
fn from_samples<T: Serialize>(samples: T, options: TracingOptions) -> Result<Self> {
SerdeArrowSchema::from_samples(samples, options)?.try_into()
}
}
Expand Down
4 changes: 2 additions & 2 deletions serde_arrow/src/internal/array_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,13 @@ impl std::fmt::Debug for ArrayBuilder {
impl ArrayBuilder {
/// Add a single record to the arrays
///
pub fn push<T: Serialize + ?Sized>(&mut self, item: &T) -> Result<()> {
pub fn push<T: Serialize>(&mut self, item: T) -> Result<()> {
self.builder.push(item)
}

/// Add multiple records to the arrays
///
pub fn extend<T: Serialize + ?Sized>(&mut self, items: &T) -> Result<()> {
pub fn extend<T: Serialize>(&mut self, items: T) -> Result<()> {
self.builder.extend(items)
}
}
Expand Down
5 changes: 1 addition & 4 deletions serde_arrow/src/internal/schema/from_samples/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@ use super::tracer::{
};

impl Tracer {
pub fn from_samples<T: Serialize + ?Sized>(
samples: &T,
options: TracingOptions,
) -> Result<Self> {
pub fn from_samples<T: Serialize>(samples: T, options: TracingOptions) -> Result<Self> {
let options = options.tracing_mode(TracingMode::FromSamples);
let mut tracer = Tracer::new(String::from("$"), String::from("$"), Arc::new(options));
samples.serialize(OuterSequenceSerializer(&mut tracer))?;
Expand Down
8 changes: 4 additions & 4 deletions serde_arrow/src/internal/schema/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ pub trait SchemaLike: Sized + Sealed {
/// fields, named `"key"` of integer type and named `"value"` of string
/// type
///
fn from_value<T: Serialize + ?Sized>(value: &T) -> Result<Self>;
fn from_value<T: Serialize>(value: T) -> Result<Self>;

/// Determine the schema from the given record type. See [`TracingOptions`] for customization
/// options.
Expand Down Expand Up @@ -271,7 +271,7 @@ pub trait SchemaLike: Sized + Sealed {
/// # #[cfg(not(has_arrow))]
/// # fn main() { }
/// ```
fn from_samples<T: Serialize + ?Sized>(samples: &T, options: TracingOptions) -> Result<Self>;
fn from_samples<T: Serialize>(samples: T, options: TracingOptions) -> Result<Self>;
}

/// A collection of fields as understood by `serde_arrow`
Expand All @@ -286,15 +286,15 @@ pub struct SerdeArrowSchema {
impl Sealed for SerdeArrowSchema {}

impl SchemaLike for SerdeArrowSchema {
fn from_value<T: Serialize + ?Sized>(value: &T) -> Result<Self> {
fn from_value<T: Serialize>(value: T) -> Result<Self> {
value::transmute(value)
}

fn from_type<'de, T: Deserialize<'de>>(options: TracingOptions) -> Result<Self> {
Tracer::from_type::<T>(options)?.to_schema()
}

fn from_samples<T: Serialize + ?Sized>(samples: &T, options: TracingOptions) -> Result<Self> {
fn from_samples<T: Serialize>(samples: T, options: TracingOptions) -> Result<Self> {
Tracer::from_samples(samples, options)?.to_schema()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ impl OuterSequenceBuilder {
}

/// Extend the builder with a sequence of items
pub fn extend<T: Serialize + ?Sized>(&mut self, value: &T) -> Result<()> {
pub fn extend<T: Serialize>(&mut self, value: T) -> Result<()> {
value.serialize(Mut(self))
}

/// Push a single item into the builder
pub fn push<T: Serialize + ?Sized>(&mut self, value: &T) -> Result<()> {
self.element(value)
pub fn push<T: Serialize>(&mut self, value: T) -> Result<()> {
self.element(&value)
}
}

Expand Down
2 changes: 1 addition & 1 deletion serde_arrow/src/internal/utils/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ impl std::hash::Hash for HashF64 {
}
}

pub fn transmute<S: Serialize + ?Sized, T: DeserializeOwned>(value: &S) -> Result<T> {
pub fn transmute<S: Serialize, T: DeserializeOwned>(value: S) -> Result<T> {
let value = value.serialize(ValueSerializer)?;
T::deserialize(ValueDeserializer::new(&value))
}
Expand Down

0 comments on commit eae1992

Please sign in to comment.