diff --git a/Cargo.toml b/Cargo.toml index c3dced9..e840284 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,6 @@ [workspace] members = [ "arrow2_convert", - "arrow2_convert_derive" + "arrow2_convert_derive", + "examples/simple" ] diff --git a/README.md b/README.md index f1840bd..eb4c893 100644 --- a/README.md +++ b/README.md @@ -21,8 +21,7 @@ pub struct Foo { name: String, } -#[test] -fn test_simple_roundtrip() { +fn main() { // an item let original_array = [ Foo { name: "hello".to_string() }, diff --git a/arrow2_convert/Cargo.toml b/arrow2_convert/Cargo.toml index dbeae06..1eaa3c2 100644 --- a/arrow2_convert/Cargo.toml +++ b/arrow2_convert/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "arrow2_convert" -version = "0.3.1" +version = "0.3.2" authors = [ "Jorge Leitao ", "Chandra Penke " @@ -13,13 +13,13 @@ description = "Convert between nested rust types and Arrow with arrow2" [dependencies] arrow2 = "0.14.1" -arrow2_convert_derive = { version = "0.3.0", path = "../arrow2_convert_derive", optional = true } +arrow2_convert_derive = { version = "0.3.2", path = "../arrow2_convert_derive", optional = true } chrono = { version = "0.4", default_features = false, features = ["std"] } err-derive = "0.3" trybuild = "1.0" [dev-dependencies] -arrow2_convert_derive = { version = "0.3.1", path = "../arrow2_convert_derive" } +arrow2_convert_derive = { version = "0.3.2", path = "../arrow2_convert_derive" } [features] default = [ "derive" ] diff --git a/arrow2_convert_derive/Cargo.toml b/arrow2_convert_derive/Cargo.toml index ba6df90..3a92f82 100644 --- a/arrow2_convert_derive/Cargo.toml +++ b/arrow2_convert_derive/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "arrow2_convert_derive" -version = "0.3.1" +version = "0.3.2" authors = [ "Jorge Leitao ", "Chandra Penke " diff --git a/examples/simple/Cargo.toml b/examples/simple/Cargo.toml new file mode 100644 index 0000000..e529d7e --- /dev/null +++ b/examples/simple/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "arrow2_convert_example_simple" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +arrow2 = "0.14" +arrow2_convert = { version = "0.3", path = "../../arrow2_convert" } diff --git a/examples/simple/src/main.rs b/examples/simple/src/main.rs new file mode 100644 index 0000000..f2f0a99 --- /dev/null +++ b/examples/simple/src/main.rs @@ -0,0 +1,38 @@ +/// Simple example +use arrow2::array::Array; +use arrow2_convert::{deserialize::TryIntoCollection, serialize::TryIntoArrow, ArrowField}; + +#[derive(Debug, Clone, PartialEq, Eq, ArrowField)] +pub struct Foo { + name: String, +} + +fn main() { + // an item + let original_array = [ + Foo { + name: "hello".to_string(), + }, + Foo { + name: "one more".to_string(), + }, + Foo { + name: "good bye".to_string(), + }, + ]; + + // serialize to an arrow array. try_into_arrow() is enabled by the TryIntoArrow trait + let arrow_array: Box = original_array.try_into_arrow().unwrap(); + + // which can be cast to an Arrow StructArray and be used for all kinds of IPC, FFI, etc. + // supported by `arrow2` + let struct_array = arrow_array + .as_any() + .downcast_ref::() + .unwrap(); + assert_eq!(struct_array.len(), 3); + + // deserialize back to our original vector via TryIntoCollection trait. + let round_trip_array: Vec = arrow_array.try_into_collection().unwrap(); + assert_eq!(round_trip_array, original_array); +}