[ 
https://issues.apache.org/jira/browse/ARROW-2384?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16426552#comment-16426552
 ] 

ASF GitHub Bot commented on ARROW-2384:
---------------------------------------

xhochy closed pull request #1818: ARROW-2384: [Rust] Additional test & Trait 
standardization
URL: https://github.com/apache/arrow/pull/1818
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/rust/src/array.rs b/rust/src/array.rs
index 7fd343346..1c0a653d7 100644
--- a/rust/src/array.rs
+++ b/rust/src/array.rs
@@ -42,7 +42,7 @@ pub enum ArrayData {
 }
 
 macro_rules! arraydata_from_primitive {
-    ($DT:ty, $AT:ident) => {
+    ($DT: ty, $AT: ident) => {
         impl From<Vec<$DT>> for ArrayData {
             fn from(v: Vec<$DT>) -> Self {
                 ArrayData::$AT(Buffer::from(v))
@@ -91,7 +91,7 @@ impl Array {
 }
 
 macro_rules! array_from_primitive {
-    ($DT:ty) => {
+    ($DT: ty) => {
         impl From<Vec<$DT>> for Array {
             fn from(v: Vec<$DT>) -> Self {
                 Array {
@@ -117,7 +117,7 @@ array_from_primitive!(i32);
 array_from_primitive!(i64);
 
 macro_rules! array_from_optional_primitive {
-    ($DT:ty, $DEFAULT:expr) => {
+    ($DT: ty, $DEFAULT: expr) => {
         impl From<Vec<Option<$DT>>> for Array {
             fn from(v: Vec<Option<$DT>>) -> Self {
                 let mut null_count = 0;
diff --git a/rust/src/buffer.rs b/rust/src/buffer.rs
index 7d5cc7c49..517583e90 100644
--- a/rust/src/buffer.rs
+++ b/rust/src/buffer.rs
@@ -92,7 +92,7 @@ where
 }
 
 macro_rules! array_from_primitive {
-    ($DT:ty) => {
+    ($DT: ty) => {
         impl From<Vec<$DT>> for Buffer<$DT> {
             fn from(v: Vec<$DT>) -> Self {
                 // allocate aligned memory buffer
diff --git a/rust/src/datatypes.rs b/rust/src/datatypes.rs
index 4f022ba45..8589a8431 100644
--- a/rust/src/datatypes.rs
+++ b/rust/src/datatypes.rs
@@ -15,6 +15,7 @@
 // specific language governing permissions and limitations
 // under the License.
 
+use std::fmt;
 use serde_json;
 use serde_json::Value;
 
@@ -201,6 +202,12 @@ impl Field {
     }
 }
 
+impl fmt::Display for Field {
+    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+        write!(f, "{}: {:?}", self.name, self.data_type)
+    }
+}
+
 #[derive(Debug, Clone)]
 pub struct Schema {
     pub columns: Vec<Field>,
@@ -223,10 +230,15 @@ impl Schema {
             .enumerate()
             .find(|&(_, c)| c.name == name)
     }
+}
 
-    pub fn to_string(&self) -> String {
-        let s: Vec<String> = self.columns.iter().map(|c| 
c.to_string()).collect();
-        s.join(",")
+impl fmt::Display for Schema {
+    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+        f.write_str(&self.columns
+            .iter()
+            .map(|c| c.to_string())
+            .collect::<Vec<String>>()
+            .join(", "))
     }
 }
 
@@ -311,4 +323,21 @@ mod tests {
         let dt = DataType::from(&value).unwrap();
         assert_eq!(DataType::Int32, dt);
     }
+
+    #[test]
+    fn create_schema_string() {
+        let _person = Schema::new(vec![
+            Field::new("first_name", DataType::Utf8, false),
+            Field::new("last_name", DataType::Utf8, false),
+            Field::new(
+                "address",
+                DataType::Struct(vec![
+                    Field::new("street", DataType::Utf8, false),
+                    Field::new("zip", DataType::UInt16, false),
+                ]),
+                false,
+            ),
+        ]);
+        assert_eq!(_person.to_string(), "first_name: Utf8, last_name: Utf8, 
address: Struct([Field { name: \"street\", data_type: Utf8, nullable: false }, 
Field { name: \"zip\", data_type: UInt16, nullable: false }])")
+    }
 }


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


> Rust: Use Traits rather than defining methods directly
> ------------------------------------------------------
>
>                 Key: ARROW-2384
>                 URL: https://issues.apache.org/jira/browse/ARROW-2384
>             Project: Apache Arrow
>          Issue Type: Improvement
>          Components: Rust
>            Reporter: Maximilian Roos
>            Assignee: Maximilian Roos
>            Priority: Trivial
>              Labels: pull-request-available
>             Fix For: 0.10.0
>
>




--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to