From 0755311edc8c82fdd69257f0544d216fe08bb34e Mon Sep 17 00:00:00 2001 From: TomtheCoder2 Date: Fri, 7 Jun 2024 20:32:35 +0200 Subject: [PATCH] better casting error messages --- src/value.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/value.rs b/src/value.rs index 2fa76d6..838e511 100644 --- a/src/value.rs +++ b/src/value.rs @@ -505,7 +505,7 @@ impl TryFrom for f32 { match value { Value::Float(f) => Ok(f), Value::Long(l) => Ok(l as f32), - _ => Err("Invalid type".to_string()), + _ => Err(format!("Could not convert {} to float!", value.get_type())), } } } @@ -517,7 +517,7 @@ impl TryFrom for i64 { match value { Value::Long(l) => Ok(l), Value::Float(f) => Ok(f as i64), - _ => Err("Invalid type".to_string()), + _ => Err(format!("Could not convert {} to int!", value.get_type())), } } } @@ -529,7 +529,7 @@ impl TryFrom for i32 { match value { Value::Long(l) => Ok(l as i32), Value::Float(f) => Ok(f as i32), - _ => Err("Invalid type".to_string()), + _ => Err(format!("Could not convert {} to int!", value.get_type())), } } } @@ -540,7 +540,7 @@ impl TryFrom for bool { fn try_from(value: Value) -> Result { match value { Value::Bool(b) => Ok(b), - _ => Err("Invalid type".to_string()), + _ => Err(format!("Could not convert {} to bool!", value.get_type())), } } } @@ -551,7 +551,7 @@ impl TryFrom for String { fn try_from(value: Value) -> Result { match value { Value::PhoenixString(s) => Ok(s), - _ => Err("Invalid type".to_string()), + _ => Err(format!("Could not convert {} to string!", value.get_type())), } } }