diff options
author | Alex Crichton <alex@alexcrichton.com> | 2019-08-13 14:36:26 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-08-13 14:36:26 -0500 |
commit | d03b251af5f935ea8363ebc59f1caddf99feb790 (patch) | |
tree | 97d7448d1b39e4a0de74033c27036f02fcac5698 | |
parent | 208f4a9ce9178a4233f1886c2fdfae05e001a2d0 (diff) | |
parent | f883457334fee8006752256e96171a4b4a428883 (diff) | |
download | milf-rs-d03b251af5f935ea8363ebc59f1caddf99feb790.tar.gz milf-rs-d03b251af5f935ea8363ebc59f1caddf99feb790.zip |
Merge pull request #319 from NickHackman/modernize-enum-discriminant-comparison
Simplified Logic when comparing discriminants
-rw-r--r-- | src/de.rs | 14 | ||||
-rw-r--r-- | src/value.rs | 13 |
2 files changed, 4 insertions, 23 deletions
@@ -8,6 +8,7 @@ use std::borrow::Cow; use std::error; use std::f64; use std::fmt; +use std::mem::discriminant; use std::str; use std::vec; @@ -2057,17 +2058,6 @@ impl<'a> E<'a> { impl<'a> Value<'a> { fn same_type(&self, other: &Value<'a>) -> bool { - match (&self.e, &other.e) { - (&E::String(..), &E::String(..)) - | (&E::Integer(..), &E::Integer(..)) - | (&E::Float(..), &E::Float(..)) - | (&E::Boolean(..), &E::Boolean(..)) - | (&E::Datetime(..), &E::Datetime(..)) - | (&E::Array(..), &E::Array(..)) - | (&E::InlineTable(..), &E::InlineTable(..)) => true, - (&E::DottedTable(..), &E::DottedTable(..)) => true, - - _ => false, - } + discriminant(&self.e) == discriminant(&other.e) } } diff --git a/src/value.rs b/src/value.rs index 00ce703..6f940b4 100644 --- a/src/value.rs +++ b/src/value.rs @@ -3,6 +3,7 @@ use std::collections::{BTreeMap, HashMap}; use std::fmt; use std::hash::Hash; +use std::mem::discriminant; use std::ops; use std::str::FromStr; use std::vec; @@ -212,17 +213,7 @@ impl Value { /// Tests whether this and another value have the same type. pub fn same_type(&self, other: &Value) -> bool { - match (self, other) { - (&Value::String(..), &Value::String(..)) - | (&Value::Integer(..), &Value::Integer(..)) - | (&Value::Float(..), &Value::Float(..)) - | (&Value::Boolean(..), &Value::Boolean(..)) - | (&Value::Datetime(..), &Value::Datetime(..)) - | (&Value::Array(..), &Value::Array(..)) - | (&Value::Table(..), &Value::Table(..)) => true, - - _ => false, - } + discriminant(self) == discriminant(other) } /// Returns a human-readable representation of the type of this value. |