uninum 0.1.1

A robust, ergonomic unified number type for Rust with automatic overflow handling, type promotion, and cross-type consistency.
Documentation
use std::convert::TryFrom;

use uninum::{Number, TryFromNumberError};

#[test]
fn f64_to_i64_accepts_min_boundary() {
    let min_as_float = -9_223_372_036_854_775_808.0_f64; // -2^63
    let value = i64::try_from(Number::from(min_as_float)).expect("i64::MIN should convert");
    assert_eq!(value, i64::MIN);
}

#[test]
fn f64_to_i64_rejects_exclusive_max_boundary() {
    let err = i64::try_from(Number::from(9_223_372_036_854_775_808.0_f64)).unwrap_err();
    assert!(matches!(err, TryFromNumberError::OutOfRange { target, .. } if target == "i64"));
}

#[test]
fn f64_to_u64_rejects_exclusive_max_boundary() {
    let err = u64::try_from(Number::from(18_446_744_073_709_551_616.0_f64)).unwrap_err();
    assert!(matches!(err, TryFromNumberError::OutOfRange { target, .. } if target == "u64"));
}

#[test]
fn try_from_number_for_f64_rejects_non_representable_ints() {
    let err = f64::try_from(Number::from(u64::MAX)).unwrap_err();
    assert!(matches!(err, TryFromNumberError::TypeMismatch { .. }));

    let err = f64::try_from(Number::from(i64::MAX)).unwrap_err();
    assert!(matches!(err, TryFromNumberError::TypeMismatch { .. }));
}