From f883457334fee8006752256e96171a4b4a428883 Mon Sep 17 00:00:00 2001 From: Nick Hackman Date: Tue, 13 Aug 2019 14:13:01 -0400 Subject: Simplified Logic when comparing discriminants Removed matches that were used to compare Enum variants for equality in favor of using discriminant from https://doc.rust-lang.org/std/mem/fn.discriminant.html introduced in Rust 1.21.0 --- src/value.rs | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) (limited to 'src/value.rs') 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. -- cgit v1.2.3