Where possible, unreflect u64s to Value::Ints
This commit is contained in:
parent
11316a9cfc
commit
407a6b267e
@ -59,6 +59,7 @@ lazy_static! {
|
||||
static ref U8_TYPEID: TypeId = TypeId::of::<u8>();
|
||||
static ref U16_TYPEID: TypeId = TypeId::of::<u16>();
|
||||
static ref U32_TYPEID: TypeId = TypeId::of::<u32>();
|
||||
static ref U64_TYPEID: TypeId = TypeId::of::<u64>();
|
||||
static ref I8_TYPEID: TypeId = TypeId::of::<i8>();
|
||||
static ref I16_TYPEID: TypeId = TypeId::of::<i16>();
|
||||
static ref I32_TYPEID: TypeId = TypeId::of::<i32>();
|
||||
@ -80,6 +81,16 @@ impl Value {
|
||||
Value::Int(u16::from_reflect(reflect.deref()).unwrap() as i64)
|
||||
} else if ti == *U32_TYPEID {
|
||||
Value::Int(u32::from_reflect(reflect.deref()).unwrap() as i64)
|
||||
} else if ti == *U64_TYPEID {
|
||||
// If we can, convert it to a native i64 value
|
||||
// If we can't (because it's bigger than i64::MAX),
|
||||
// then we have no choice but to leave it as a reflective value... :/
|
||||
// TODO I really don't like this but my hands are tied...
|
||||
let value_u64 = u64::from_reflect(reflect.deref()).unwrap();
|
||||
match i64::try_from(value_u64) {
|
||||
Ok(value_i64) => Value::Int(value_i64),
|
||||
Err(_cant) => Value::Reflective(reflect),
|
||||
}
|
||||
} else if ti == *I8_TYPEID {
|
||||
Value::Int(i8::from_reflect(reflect.deref()).unwrap() as i64)
|
||||
} else if ti == *I16_TYPEID {
|
||||
|
Loading…
Reference in New Issue
Block a user