use {
DataType, DataValue, HasDataType, IncompatibleDataType,
IsParameterMask, Result,
};
pub trait TryConvertTo<D>: Sized {
fn try_convert_to(&self, d: &D) -> Result<Self>;
}
impl<M: IsParameterMask> TryConvertTo<DataType> for DataValue<M> {
fn try_convert_to(&self, d: &DataType) -> Result<DataValue<M>> {
use self::DataType::*;
match *d {
Boolean => self.try_build_boolean(),
Int8 => self.try_build_int8(),
Int16 => self.try_build_int16(),
Int32 => self.try_build_int32(),
Int64 => self.try_build_int64(),
UInt8 => self.try_build_uint8(),
UInt16 => self.try_build_uint16(),
UInt32 => self.try_build_uint32(),
UInt64 => self.try_build_uint64(),
ParameterMask => self.try_build_parametermask(),
Invalid => IncompatibleDataType {
expected: d.clone(),
found: self.data_type(),
}
.fail(),
}
}
}
trait TryBuildBoolean: Sized {
fn try_build_boolean(&self) -> Result<Self>;
}
trait TryBuildInt8: Sized {
fn try_build_int8(&self) -> Result<Self>;
}
trait TryBuildInt16: Sized {
fn try_build_int16(&self) -> Result<Self>;
}
trait TryBuildInt32: Sized {
fn try_build_int32(&self) -> Result<Self>;
}
trait TryBuildInt64: Sized {
fn try_build_int64(&self) -> Result<Self>;
}
trait TryBuildUInt8: Sized {
fn try_build_uint8(&self) -> Result<Self>;
}
trait TryBuildUInt16: Sized {
fn try_build_uint16(&self) -> Result<Self>;
}
trait TryBuildUInt32: Sized {
fn try_build_uint32(&self) -> Result<Self>;
}
trait TryBuildUInt64: Sized {
fn try_build_uint64(&self) -> Result<Self>;
}
trait TryBuildParameterMask: Sized {
fn try_build_parametermask(&self) -> Result<Self>;
}
impl<M: IsParameterMask> TryBuildBoolean for DataValue<M> {
fn try_build_boolean(&self) -> Result<Self> {
use self::DataValue::*;
match *self {
Boolean(ref v) => Ok(Boolean(*v)),
_ => IncompatibleDataType {
found: self.data_type(),
expected: DataType::Boolean,
}
.fail(),
}
}
}
impl<M: IsParameterMask> TryBuildInt8 for DataValue<M> {
fn try_build_int8(&self) -> Result<Self> {
use self::ranges::ConvertIfInRange;
use self::DataValue::*;
match *self {
Int8(v) => Ok(Int8(v.convert_if_in_range()?)),
Int16(v) => Ok(Int8(v.convert_if_in_range()?)),
Int32(v) => Ok(Int8(v.convert_if_in_range()?)),
Int64(v) => Ok(Int8(v.convert_if_in_range()?)),
UInt8(v) => Ok(Int8(v.convert_if_in_range()?)),
UInt16(v) => Ok(Int8(v.convert_if_in_range()?)),
UInt32(v) => Ok(Int8(v.convert_if_in_range()?)),
UInt64(v) => Ok(Int8(v.convert_if_in_range()?)),
_ => IncompatibleDataType {
found: self.data_type(),
expected: DataType::Int8,
}
.fail(),
}
}
}
impl<M: IsParameterMask> TryBuildInt16 for DataValue<M> {
fn try_build_int16(&self) -> Result<Self> {
use self::ranges::ConvertIfInRange;
use self::DataValue::*;
match *self {
Int8(v) => Ok(Int16(v.convert_if_in_range()?)),
Int16(v) => Ok(Int16(v.convert_if_in_range()?)),
Int32(v) => Ok(Int16(v.convert_if_in_range()?)),
Int64(v) => Ok(Int16(v.convert_if_in_range()?)),
UInt8(v) => Ok(Int16(v.convert_if_in_range()?)),
UInt16(v) => Ok(Int16(v.convert_if_in_range()?)),
UInt32(v) => Ok(Int16(v.convert_if_in_range()?)),
UInt64(v) => Ok(Int16(v.convert_if_in_range()?)),
_ => IncompatibleDataType {
found: self.data_type(),
expected: DataType::Int16,
}
.fail(),
}
}
}
impl<M: IsParameterMask> TryBuildInt32 for DataValue<M> {
fn try_build_int32(&self) -> Result<Self> {
use self::ranges::ConvertIfInRange;
use self::DataValue::*;
match *self {
Int8(v) => Ok(Int32(v.convert_if_in_range()?)),
Int16(v) => Ok(Int32(v.convert_if_in_range()?)),
Int32(v) => Ok(Int32(v.convert_if_in_range()?)),
Int64(v) => Ok(Int32(v.convert_if_in_range()?)),
UInt8(v) => Ok(Int32(v.convert_if_in_range()?)),
UInt16(v) => Ok(Int32(v.convert_if_in_range()?)),
UInt32(v) => Ok(Int32(v.convert_if_in_range()?)),
UInt64(v) => Ok(Int32(v.convert_if_in_range()?)),
_ => IncompatibleDataType {
found: self.data_type(),
expected: DataType::Int32,
}
.fail(),
}
}
}
impl<M: IsParameterMask> TryBuildInt64 for DataValue<M> {
fn try_build_int64(&self) -> Result<Self> {
use self::ranges::ConvertIfInRange;
use self::DataValue::*;
match *self {
Int8(v) => Ok(Int64(v.convert_if_in_range()?)),
Int16(v) => Ok(Int64(v.convert_if_in_range()?)),
Int32(v) => Ok(Int64(v.convert_if_in_range()?)),
Int64(v) => Ok(Int64(v.convert_if_in_range()?)),
UInt8(v) => Ok(Int64(v.convert_if_in_range()?)),
UInt16(v) => Ok(Int64(v.convert_if_in_range()?)),
UInt32(v) => Ok(Int64(v.convert_if_in_range()?)),
UInt64(v) => Ok(Int64(v.convert_if_in_range()?)),
_ => IncompatibleDataType {
found: self.data_type(),
expected: DataType::Int64,
}
.fail(),
}
}
}
impl<M: IsParameterMask> TryBuildUInt8 for DataValue<M> {
fn try_build_uint8(&self) -> Result<Self> {
use self::ranges::ConvertIfInRange;
use self::DataValue::*;
match *self {
Int8(v) => Ok(UInt8(v.convert_if_in_range()?)),
Int16(v) => Ok(UInt8(v.convert_if_in_range()?)),
Int32(v) => Ok(UInt8(v.convert_if_in_range()?)),
Int64(v) => Ok(UInt8(v.convert_if_in_range()?)),
UInt8(v) => Ok(UInt8(v.convert_if_in_range()?)),
UInt16(v) => Ok(UInt8(v.convert_if_in_range()?)),
UInt32(v) => Ok(UInt8(v.convert_if_in_range()?)),
UInt64(v) => Ok(UInt8(v.convert_if_in_range()?)),
_ => IncompatibleDataType {
found: self.data_type(),
expected: DataType::UInt8,
}
.fail(),
}
}
}
impl<M: IsParameterMask> TryBuildUInt16 for DataValue<M> {
fn try_build_uint16(&self) -> Result<Self> {
use self::ranges::ConvertIfInRange;
use self::DataValue::*;
match *self {
Int8(v) => Ok(UInt16(v.convert_if_in_range()?)),
Int16(v) => Ok(UInt16(v.convert_if_in_range()?)),
Int32(v) => Ok(UInt16(v.convert_if_in_range()?)),
Int64(v) => Ok(UInt16(v.convert_if_in_range()?)),
UInt8(v) => Ok(UInt16(v.convert_if_in_range()?)),
UInt16(v) => Ok(UInt16(v.convert_if_in_range()?)),
UInt32(v) => Ok(UInt16(v.convert_if_in_range()?)),
UInt64(v) => Ok(UInt16(v.convert_if_in_range()?)),
_ => IncompatibleDataType {
found: self.data_type(),
expected: DataType::UInt16,
}
.fail(),
}
}
}
impl<M: IsParameterMask> TryBuildUInt32 for DataValue<M> {
fn try_build_uint32(&self) -> Result<Self> {
use self::ranges::ConvertIfInRange;
use self::DataValue::*;
match *self {
Int8(v) => Ok(UInt32(v.convert_if_in_range()?)),
Int16(v) => Ok(UInt32(v.convert_if_in_range()?)),
Int32(v) => Ok(UInt32(v.convert_if_in_range()?)),
Int64(v) => Ok(UInt32(v.convert_if_in_range()?)),
UInt8(v) => Ok(UInt32(v.convert_if_in_range()?)),
UInt16(v) => Ok(UInt32(v.convert_if_in_range()?)),
UInt32(v) => Ok(UInt32(v.convert_if_in_range()?)),
UInt64(v) => Ok(UInt32(v.convert_if_in_range()?)),
_ => IncompatibleDataType {
found: self.data_type(),
expected: DataType::UInt32,
}
.fail(),
}
}
}
impl<M: IsParameterMask> TryBuildUInt64 for DataValue<M> {
fn try_build_uint64(&self) -> Result<Self> {
use self::ranges::ConvertIfInRange;
use self::DataValue::*;
match *self {
Int8(v) => Ok(UInt64(v.convert_if_in_range()?)),
Int16(v) => Ok(UInt64(v.convert_if_in_range()?)),
Int32(v) => Ok(UInt64(v.convert_if_in_range()?)),
Int64(v) => Ok(UInt64(v.convert_if_in_range()?)),
UInt8(v) => Ok(UInt64(v.convert_if_in_range()?)),
UInt16(v) => Ok(UInt64(v.convert_if_in_range()?)),
UInt32(v) => Ok(UInt64(v.convert_if_in_range()?)),
UInt64(v) => Ok(UInt64(v.convert_if_in_range()?)),
_ => IncompatibleDataType {
found: self.data_type(),
expected: DataType::UInt64,
}
.fail(),
}
}
}
impl<M: IsParameterMask> TryBuildParameterMask for DataValue<M> {
fn try_build_parametermask(&self) -> Result<Self> {
use self::DataValue::*;
match *self {
ParameterMask(ref v) => Ok(ParameterMask(v.clone())),
_ => IncompatibleDataType {
found: self.data_type(),
expected: DataType::ParameterMask,
}
.fail(),
}
}
}
mod ranges {
use std::{i16, i32, i64, i8, u16, u32, u64, u8};
use {std, DataType, DataValue, Result, ValueOutOfRangeForType};
pub(crate) trait ConvertIfInRange<T> {
fn convert_if_in_range(&self) -> Result<T>;
}
impl<T: Clone> ConvertIfInRange<T> for T {
fn convert_if_in_range(&self) -> Result<T> {
Ok((*self).clone())
}
}
impl ConvertIfInRange<i8> for i16 {
fn convert_if_in_range(&self) -> Result<i8> {
ensure!(
*self <= i16::from(i8::MAX),
ValueOutOfRangeForType {
value: DataValue::Int16(*self),
datatype: DataType::Int8,
}
);
Ok(*self as i8)
}
}
impl ConvertIfInRange<i8> for i32 {
fn convert_if_in_range(&self) -> Result<i8> {
ensure!(
*self <= i32::from(i8::MAX),
ValueOutOfRangeForType {
value: DataValue::Int32(*self),
datatype: DataType::Int8,
}
);
Ok(*self as i8)
}
}
impl ConvertIfInRange<i8> for i64 {
fn convert_if_in_range(&self) -> Result<i8> {
ensure!(
*self <= i64::from(i8::MAX),
ValueOutOfRangeForType {
value: DataValue::Int64(*self),
datatype: DataType::Int8,
}
);
Ok(*self as i8)
}
}
impl ConvertIfInRange<i8> for u8 {
fn convert_if_in_range(&self) -> Result<i8> {
ensure!(
*self <= (i8::MAX as u8),
ValueOutOfRangeForType {
value: DataValue::UInt8(*self),
datatype: DataType::Int8,
}
);
Ok(*self as i8)
}
}
impl ConvertIfInRange<i8> for u16 {
fn convert_if_in_range(&self) -> Result<i8> {
ensure!(
*self <= (i8::MAX as u16),
ValueOutOfRangeForType {
value: DataValue::UInt16(*self),
datatype: DataType::Int8,
}
);
Ok(*self as i8)
}
}
impl ConvertIfInRange<i8> for u32 {
fn convert_if_in_range(&self) -> Result<i8> {
ensure!(
*self <= (i8::MAX as u32),
ValueOutOfRangeForType {
value: DataValue::UInt32(*self),
datatype: DataType::Int8,
}
);
Ok(*self as i8)
}
}
impl ConvertIfInRange<i8> for u64 {
fn convert_if_in_range(&self) -> Result<i8> {
ensure!(
*self <= (i8::MAX as u64),
ValueOutOfRangeForType {
value: DataValue::UInt64(*self),
datatype: DataType::Int8,
}
);
Ok(*self as i8)
}
}
impl ConvertIfInRange<i16> for i8 {
fn convert_if_in_range(&self) -> Result<i16> {
Ok(i16::from(*self))
}
}
impl ConvertIfInRange<i16> for i32 {
fn convert_if_in_range(&self) -> Result<i16> {
ensure!(
*self <= i32::from(i16::MAX)
&& *self >= i32::from(i16::MIN),
ValueOutOfRangeForType {
value: DataValue::Int32(*self),
datatype: DataType::Int16,
}
);
Ok(*self as i16)
}
}
impl ConvertIfInRange<i16> for i64 {
fn convert_if_in_range(&self) -> Result<i16> {
ensure!(
*self <= i64::from(i16::MAX)
&& *self >= i64::from(i16::MIN),
ValueOutOfRangeForType {
value: DataValue::Int64(*self),
datatype: DataType::Int16,
}
);
Ok(*self as i16)
}
}
impl ConvertIfInRange<i16> for u8 {
fn convert_if_in_range(&self) -> Result<i16> {
ensure!(
*self <= (i16::MAX as u8),
ValueOutOfRangeForType {
value: DataValue::UInt8(*self),
datatype: DataType::Int16,
}
);
Ok(i16::from(*self))
}
}
impl ConvertIfInRange<i16> for u16 {
fn convert_if_in_range(&self) -> Result<i16> {
ensure!(
*self <= (i16::MAX as u16),
ValueOutOfRangeForType {
value: DataValue::UInt16(*self),
datatype: DataType::Int16,
}
);
Ok(*self as i16)
}
}
impl ConvertIfInRange<i16> for u32 {
fn convert_if_in_range(&self) -> Result<i16> {
ensure!(
*self <= (i16::MAX as u32),
ValueOutOfRangeForType {
value: DataValue::UInt32(*self),
datatype: DataType::Int16,
}
);
Ok(*self as i16)
}
}
impl ConvertIfInRange<i16> for u64 {
fn convert_if_in_range(&self) -> Result<i16> {
ensure!(
*self <= (i16::MAX as u64),
ValueOutOfRangeForType {
value: DataValue::UInt64(*self),
datatype: DataType::Int16,
}
);
Ok(*self as i16)
}
}
impl ConvertIfInRange<i32> for i8 {
fn convert_if_in_range(&self) -> Result<i32> {
Ok(i32::from(*self))
}
}
impl ConvertIfInRange<i32> for i16 {
fn convert_if_in_range(&self) -> Result<i32> {
Ok(i32::from(*self))
}
}
impl ConvertIfInRange<i32> for i64 {
fn convert_if_in_range(&self) -> Result<i32> {
ensure!(
*self <= i64::from(i32::MAX)
&& *self >= i64::from(i32::MIN),
ValueOutOfRangeForType {
value: DataValue::Int64(*self),
datatype: DataType::Int32,
}
);
Ok(*self as i32)
}
}
impl ConvertIfInRange<i32> for u8 {
fn convert_if_in_range(&self) -> Result<i32> {
ensure!(
*self <= (i32::MAX as u8),
ValueOutOfRangeForType {
value: DataValue::UInt8(*self),
datatype: DataType::Int32,
}
);
Ok(i32::from(*self))
}
}
impl ConvertIfInRange<i32> for u16 {
fn convert_if_in_range(&self) -> Result<i32> {
ensure!(
*self <= (i32::MAX as u16),
ValueOutOfRangeForType {
value: DataValue::UInt16(*self),
datatype: DataType::Int32,
}
);
Ok(i32::from(*self))
}
}
impl ConvertIfInRange<i32> for u32 {
fn convert_if_in_range(&self) -> Result<i32> {
ensure!(
*self <= (i32::MAX as u32),
ValueOutOfRangeForType {
value: DataValue::UInt32(*self),
datatype: DataType::Int32,
}
);
Ok(*self as i32)
}
}
impl ConvertIfInRange<i32> for u64 {
fn convert_if_in_range(&self) -> Result<i32> {
ensure!(
*self <= (i32::MAX as u64),
ValueOutOfRangeForType {
value: DataValue::UInt64(*self),
datatype: DataType::Int32,
}
);
Ok(*self as i32)
}
}
impl ConvertIfInRange<i64> for i8 {
fn convert_if_in_range(&self) -> Result<i64> {
Ok(i64::from(*self))
}
}
impl ConvertIfInRange<i64> for i16 {
fn convert_if_in_range(&self) -> Result<i64> {
Ok(i64::from(*self))
}
}
impl ConvertIfInRange<i64> for i32 {
fn convert_if_in_range(&self) -> Result<i64> {
Ok(i64::from(*self))
}
}
impl ConvertIfInRange<i64> for u8 {
fn convert_if_in_range(&self) -> Result<i64> {
Ok(i64::from(*self))
}
}
impl ConvertIfInRange<i64> for u16 {
fn convert_if_in_range(&self) -> Result<i64> {
Ok(i64::from(*self))
}
}
impl ConvertIfInRange<i64> for u32 {
fn convert_if_in_range(&self) -> Result<i64> {
Ok(i64::from(*self))
}
}
impl ConvertIfInRange<i64> for u64 {
fn convert_if_in_range(&self) -> Result<i64> {
ensure!(
*self <= (std::i64::MAX as u64),
ValueOutOfRangeForType {
value: DataValue::UInt64(*self),
datatype: DataType::Int64,
}
);
Ok(*self as i64)
}
}
impl ConvertIfInRange<u8> for i8 {
fn convert_if_in_range(&self) -> Result<u8> {
ensure!(
*self >= 0,
ValueOutOfRangeForType {
value: DataValue::Int8(*self),
datatype: DataType::UInt8,
}
);
Ok(*self as u8)
}
}
impl ConvertIfInRange<u8> for i16 {
fn convert_if_in_range(&self) -> Result<u8> {
ensure!(
*self >= 0 && *self <= i16::from(u8::MAX),
ValueOutOfRangeForType {
value: DataValue::Int16(*self),
datatype: DataType::UInt8,
}
);
Ok(*self as u8)
}
}
impl ConvertIfInRange<u8> for i32 {
fn convert_if_in_range(&self) -> Result<u8> {
ensure!(
*self >= 0 && *self <= i32::from(u8::MAX),
ValueOutOfRangeForType {
value: DataValue::Int32(*self),
datatype: DataType::UInt8,
}
);
Ok(*self as u8)
}
}
impl ConvertIfInRange<u8> for i64 {
fn convert_if_in_range(&self) -> Result<u8> {
ensure!(
*self >= 0 && *self <= i64::from(u8::MAX),
ValueOutOfRangeForType {
value: DataValue::Int64(*self),
datatype: DataType::UInt8,
}
);
Ok(*self as u8)
}
}
impl ConvertIfInRange<u8> for u16 {
fn convert_if_in_range(&self) -> Result<u8> {
ensure!(
*self <= (i8::MAX as u16),
ValueOutOfRangeForType {
value: DataValue::UInt16(*self),
datatype: DataType::UInt8,
}
);
Ok(*self as u8)
}
}
impl ConvertIfInRange<u8> for u32 {
fn convert_if_in_range(&self) -> Result<u8> {
ensure!(
*self <= (i8::MAX as u32),
ValueOutOfRangeForType {
value: DataValue::UInt32(*self),
datatype: DataType::UInt8,
}
);
Ok(*self as u8)
}
}
impl ConvertIfInRange<u8> for u64 {
fn convert_if_in_range(&self) -> Result<u8> {
ensure!(
*self <= (i8::MAX as u64),
ValueOutOfRangeForType {
value: DataValue::UInt64(*self),
datatype: DataType::UInt8,
}
);
Ok(*self as u8)
}
}
impl ConvertIfInRange<u16> for i8 {
fn convert_if_in_range(&self) -> Result<u16> {
ensure!(
*self >= 0,
ValueOutOfRangeForType {
value: DataValue::Int8(*self),
datatype: DataType::UInt16,
}
);
Ok(*self as u16)
}
}
impl ConvertIfInRange<u16> for i16 {
fn convert_if_in_range(&self) -> Result<u16> {
ensure!(
*self >= 0,
ValueOutOfRangeForType {
value: DataValue::Int16(*self),
datatype: DataType::UInt16,
}
);
Ok(*self as u16)
}
}
impl ConvertIfInRange<u16> for i32 {
fn convert_if_in_range(&self) -> Result<u16> {
ensure!(
*self >= 0 && *self <= i32::from(u16::MAX),
ValueOutOfRangeForType {
value: DataValue::Int32(*self),
datatype: DataType::UInt16,
}
);
Ok(*self as u16)
}
}
impl ConvertIfInRange<u16> for i64 {
fn convert_if_in_range(&self) -> Result<u16> {
ensure!(
*self >= 0 && *self <= i64::from(u16::MAX),
ValueOutOfRangeForType {
value: DataValue::Int64(*self),
datatype: DataType::UInt16,
}
);
Ok(*self as u16)
}
}
impl ConvertIfInRange<u16> for u8 {
fn convert_if_in_range(&self) -> Result<u16> {
Ok(u16::from(*self))
}
}
impl ConvertIfInRange<u16> for u32 {
fn convert_if_in_range(&self) -> Result<u16> {
ensure!(
*self <= u32::from(u16::MAX),
ValueOutOfRangeForType {
value: DataValue::UInt32(*self),
datatype: DataType::UInt16,
}
);
Ok(*self as u16)
}
}
impl ConvertIfInRange<u16> for u64 {
fn convert_if_in_range(&self) -> Result<u16> {
ensure!(
*self <= u64::from(u16::MAX),
ValueOutOfRangeForType {
value: DataValue::UInt64(*self),
datatype: DataType::UInt16,
}
);
Ok(*self as u16)
}
}
impl ConvertIfInRange<u32> for i8 {
fn convert_if_in_range(&self) -> Result<u32> {
ensure!(
*self >= 0,
ValueOutOfRangeForType {
value: DataValue::Int8(*self),
datatype: DataType::UInt32,
}
);
Ok(*self as u32)
}
}
impl ConvertIfInRange<u32> for i16 {
fn convert_if_in_range(&self) -> Result<u32> {
ensure!(
*self >= 0,
ValueOutOfRangeForType {
value: DataValue::Int16(*self),
datatype: DataType::UInt32,
}
);
Ok(*self as u32)
}
}
impl ConvertIfInRange<u32> for i32 {
fn convert_if_in_range(&self) -> Result<u32> {
ensure!(
*self >= 0,
ValueOutOfRangeForType {
value: DataValue::Int32(*self),
datatype: DataType::UInt32,
}
);
Ok(*self as u32)
}
}
impl ConvertIfInRange<u32> for i64 {
fn convert_if_in_range(&self) -> Result<u32> {
ensure!(
*self >= 0 && *self <= i64::from(u32::MAX),
ValueOutOfRangeForType {
value: DataValue::Int64(*self),
datatype: DataType::UInt32,
}
);
Ok(*self as u32)
}
}
impl ConvertIfInRange<u32> for u8 {
fn convert_if_in_range(&self) -> Result<u32> {
Ok(u32::from(*self))
}
}
impl ConvertIfInRange<u32> for u16 {
fn convert_if_in_range(&self) -> Result<u32> {
Ok(u32::from(*self))
}
}
impl ConvertIfInRange<u32> for u64 {
fn convert_if_in_range(&self) -> Result<u32> {
ensure!(
*self <= u64::from(u32::MAX),
ValueOutOfRangeForType {
value: DataValue::UInt64(*self),
datatype: DataType::UInt32,
}
);
Ok(*self as u32)
}
}
impl ConvertIfInRange<u64> for i8 {
fn convert_if_in_range(&self) -> Result<u64> {
ensure!(
*self >= 0,
ValueOutOfRangeForType {
value: DataValue::Int8(*self),
datatype: DataType::UInt64,
}
);
Ok(*self as u64)
}
}
impl ConvertIfInRange<u64> for i16 {
fn convert_if_in_range(&self) -> Result<u64> {
ensure!(
*self >= 0,
ValueOutOfRangeForType {
value: DataValue::Int16(*self),
datatype: DataType::UInt64,
}
);
Ok(*self as u64)
}
}
impl ConvertIfInRange<u64> for i32 {
fn convert_if_in_range(&self) -> Result<u64> {
ensure!(
*self >= 0,
ValueOutOfRangeForType {
value: DataValue::Int32(*self),
datatype: DataType::UInt64,
}
);
Ok(*self as u64)
}
}
impl ConvertIfInRange<u64> for i64 {
fn convert_if_in_range(&self) -> Result<u64> {
ensure!(
*self >= 0,
ValueOutOfRangeForType {
value: DataValue::Int64(*self),
datatype: DataType::UInt64,
}
);
Ok(*self as u64)
}
}
impl ConvertIfInRange<u64> for u8 {
fn convert_if_in_range(&self) -> Result<u64> {
Ok(u64::from(*self))
}
}
impl ConvertIfInRange<u64> for u16 {
fn convert_if_in_range(&self) -> Result<u64> {
Ok(u64::from(*self))
}
}
impl ConvertIfInRange<u64> for u32 {
fn convert_if_in_range(&self) -> Result<u64> {
Ok(u64::from(*self))
}
}
}