tustvold commented on code in PR #1647:
URL: https://github.com/apache/arrow-rs/pull/1647#discussion_r866529920
##########
arrow/src/datatypes/field.rs:
##########
@@ -39,6 +41,50 @@ pub struct Field {
metadata: Option<BTreeMap<String, String>>,
}
+impl PartialEq for Field {
Review Comment:
We could probably do with a comment to say why we are implementing these
instead of an auto-derive
##########
arrow/src/datatypes/field.rs:
##########
@@ -39,6 +41,50 @@ pub struct Field {
metadata: Option<BTreeMap<String, String>>,
}
+impl PartialEq for Field {
+ fn eq(&self, other: &Self) -> bool {
+ self.name == other.name
+ && self.data_type == other.data_type
+ && self.nullable == other.nullable
+ && self.metadata == other.metadata
+ }
+}
+
+impl Eq for Field {}
+
+impl PartialOrd for Field {
+ fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
+ Some(self.cmp(other))
+ }
+}
+
+impl Ord for Field {
+ fn cmp(&self, other: &Self) -> Ordering {
+ let mut ord = self.name.cmp(other.name());
Review Comment:
You can use https://doc.rust-lang.org/std/cmp/enum.Ordering.html#method.then
to make this shorter, but this is also fine
##########
arrow/src/datatypes/field.rs:
##########
@@ -39,6 +41,50 @@ pub struct Field {
metadata: Option<BTreeMap<String, String>>,
}
+impl PartialEq for Field {
+ fn eq(&self, other: &Self) -> bool {
+ self.name == other.name
+ && self.data_type == other.data_type
+ && self.nullable == other.nullable
+ && self.metadata == other.metadata
+ }
+}
+
+impl Eq for Field {}
+
+impl PartialOrd for Field {
+ fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
+ Some(self.cmp(other))
+ }
+}
+
+impl Ord for Field {
+ fn cmp(&self, other: &Self) -> Ordering {
+ let mut ord = self.name.cmp(other.name());
+ if let Ordering::Equal = ord {
+ ord = self.data_type.cmp(other.data_type());
+
+ if let Ordering::Equal = ord {
+ ord = self.nullable.cmp(&other.nullable);
+
+ if let Ordering::Equal = ord {
+ ord = self.metadata.cmp(&other.metadata);
+ }
+ }
+ }
+ ord
+ }
+}
+
+impl Hash for Field {
+ fn hash<H: Hasher>(&self, state: &mut H) {
+ self.name.hash(state);
+ self.data_type.hash(state);
+ self.nullable.hash(state);
+ self.metadata.hash(state);
+ }
+}
+
Review Comment:
Maybe a simple test?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]