| 256 | |
| 257 | impl DataValueExt for DataValue { |
| 258 | fn int(n: i128, ty: Type) -> ValueResult<Self> { |
| 259 | if ty.is_vector() { |
| 260 | // match ensures graceful failure since read_from_slice_ne() |
| 261 | // panics on anything other than 8 and 16 bytes |
| 262 | match ty.bytes() { |
| 263 | 8 | 16 => Ok(DataValue::read_from_slice_ne(&n.to_ne_bytes(), ty)), |
| 264 | _ => Err(ValueError::InvalidType(ValueTypeClass::Vector, ty)), |
| 265 | } |
| 266 | } else if ty.is_int() { |
| 267 | DataValue::from_integer(n, ty).map_err(|_| ValueError::InvalidValue(ty)) |
| 268 | } else { |
| 269 | Err(ValueError::InvalidType(ValueTypeClass::Integer, ty)) |
| 270 | } |
| 271 | } |
| 272 | |
| 273 | fn into_int_signed(self) -> ValueResult<i128> { |
| 274 | match self { |