/// Exhaustively matching on Number in tests
///
/// If you want to ensure that you exhaustively handle every variant, you can
/// match on the hidden `Number::__NonExhaustive(x)` variant by using the
/// `x.never() -> !` method.
///
///
/// Matching on this variant means that your code may break when RON is
/// upgraded or when feature unification enables further variants in the
/// Number enum than your code expects.
///
///
/// It is your responsibility to only *ever* match on `Number::__NonExhaustive`
/// inside tests, e.g. by using `#[cfg(test)]` on the particular match arm, to
/// ensure that only your tests break (e.g. in CI) when your code is not
/// exhaustively matching on every variant, e.g. after a version upgrade or
/// feature unification.
///
#[derive(Copy, Clone, Debug, PartialEq, PartialOrd, Eq, Hash, Ord)]
#[cfg_attr(doc, non_exhaustive)]
pub enum Number {
I8(i8),
I16(i16),
I32(i32),
I64(i64),
#[cfg(feature = "integer128")]
I128(i128),
U8(u8),
U16(u16),
U32(u32),
U64(u64),
#[cfg(feature = "integer128")]
U128(u128),
F32(F32),
F64(F64),
#[cfg(not(doc))]
#[allow(private_interfaces)]
__NonExhaustive(private::Never),
}
mod private {
#[derive(Debug, PartialEq, PartialOrd, Eq, Hash, Ord)]
enum _Never {}
#[derive(Copy, Clone, Debug, PartialEq, PartialOrd, Eq, Hash, Ord)]
pub struct Never {
never: &'static _Never,
}
impl Never {
pub fn never(self) -> ! {
match *self.never {}
}
}
#[cfg(not(feature = "integer128"))]
/// ```compile_fail
/// # use ron::Number;
/// fn match_number(x: Number) {
/// match x {
/// Number::I8(v) => println!("i8: {}", v),
/// Number::I16(v) => println!("i16: {}", v),
/// Number::I32(v) => println!("i32: {}", v),
/// Number::I64(v) => println!("i64: {}", v),
/// Number::U8(v) => println!("u8: {}", v),
/// Number::U16(v) => println!("u16: {}", v),
/// Number::U32(v) => println!("u32: {}", v),
/// Number::U64(v) => println!("u64: {}", v),
/// Number::F32(v) => println!("f32: {}", v.0),
/// Number::F64(v) => println!("f64: {}", v.0),
/// }
/// }
/// ```
fn _assert_non_exhaustive_check_fails_not_integer128() {}
#[cfg(feature = "integer128")]
/// ```compile_fail
/// # use ron::Number;
/// fn match_number(x: Number) {
/// match x {
/// Number::I8(v) => println!("i8: {}", v),
/// Number::I16(v) => println!("i16: {}", v),
/// Number::I32(v) => println!("i32: {}", v),
/// Number::I64(v) => println!("i64: {}", v),
/// Number::I128(v) => println!("i128: {}", v),
/// Number::U8(v) => println!("u8: {}", v),
/// Number::U16(v) => println!("u16: {}", v),
/// Number::U32(v) => println!("u32: {}", v),
/// Number::U64(v) => println!("u64: {}", v),
/// Number::U128(v) => println!("u128: {}", v),
/// Number::F32(v) => println!("f32: {}", v.0),
/// Number::F64(v) => println!("f64: {}", v.0),
/// }
/// }
/// ```
fn _assert_non_exhaustive_check_fails_integer128() {}
}
impl Serialize for Number {
fn serialize