diff --git a/serde/Cargo.toml b/serde/Cargo.toml index 3a69be3a..3bd5dcac 100644 --- a/serde/Cargo.toml +++ b/serde/Cargo.toml @@ -12,11 +12,6 @@ keywords = ["serde", "serialization"] [features] nightly = [] nightly-testing = ["clippy", "nightly"] -num-bigint = ["num/bigint"] -num-complex = ["num/complex"] -num-impls = ["num-bigint", "num-complex", "num-rational"] -num-rational = ["num/rational"] [dependencies] clippy = { version = "^0.*", optional = true } -num = { version = "^0.1.27", default-features = false } diff --git a/serde/src/de/from_primitive.rs b/serde/src/de/from_primitive.rs new file mode 100644 index 00000000..5bd3e531 --- /dev/null +++ b/serde/src/de/from_primitive.rs @@ -0,0 +1,406 @@ +// Copyright 2013-2014 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// Extracted from https://github.com/rust-num/num. + +use std::{usize, u8, u16, u32, u64}; +use std::{isize, i8, i16, i32, i64}; +use std::{f32, f64}; +use std::mem::size_of; + +/// Numbers which have upper and lower bounds +pub trait Bounded { + // FIXME (#5527): These should be associated constants + /// returns the smallest finite number this type can represent + fn min_value() -> Self; + /// returns the largest finite number this type can represent + fn max_value() -> Self; +} + +macro_rules! bounded_impl { + ($t:ty, $min:expr, $max:expr) => { + impl Bounded for $t { + #[inline] + fn min_value() -> $t { $min } + + #[inline] + fn max_value() -> $t { $max } + } + } +} + +bounded_impl!(usize, usize::MIN, usize::MAX); +bounded_impl!(u8, u8::MIN, u8::MAX); +bounded_impl!(u16, u16::MIN, u16::MAX); +bounded_impl!(u32, u32::MIN, u32::MAX); +bounded_impl!(u64, u64::MIN, u64::MAX); + +bounded_impl!(isize, isize::MIN, isize::MAX); +bounded_impl!(i8, i8::MIN, i8::MAX); +bounded_impl!(i16, i16::MIN, i16::MAX); +bounded_impl!(i32, i32::MIN, i32::MAX); +bounded_impl!(i64, i64::MIN, i64::MAX); + +bounded_impl!(f32, f32::MIN, f32::MAX); +bounded_impl!(f64, f64::MIN, f64::MAX); + +/// A generic trait for converting a value to a number. +pub trait ToPrimitive { + /// Converts the value of `self` to an `isize`. + #[inline] + fn to_isize(&self) -> Option { + self.to_i64().and_then(|x| x.to_isize()) + } + + /// Converts the value of `self` to an `i8`. + #[inline] + fn to_i8(&self) -> Option { + self.to_i64().and_then(|x| x.to_i8()) + } + + /// Converts the value of `self` to an `i16`. + #[inline] + fn to_i16(&self) -> Option { + self.to_i64().and_then(|x| x.to_i16()) + } + + /// Converts the value of `self` to an `i32`. + #[inline] + fn to_i32(&self) -> Option { + self.to_i64().and_then(|x| x.to_i32()) + } + + /// Converts the value of `self` to an `i64`. + fn to_i64(&self) -> Option; + + /// Converts the value of `self` to a `usize`. + #[inline] + fn to_usize(&self) -> Option { + self.to_u64().and_then(|x| x.to_usize()) + } + + /// Converts the value of `self` to an `u8`. + #[inline] + fn to_u8(&self) -> Option { + self.to_u64().and_then(|x| x.to_u8()) + } + + /// Converts the value of `self` to an `u16`. + #[inline] + fn to_u16(&self) -> Option { + self.to_u64().and_then(|x| x.to_u16()) + } + + /// Converts the value of `self` to an `u32`. + #[inline] + fn to_u32(&self) -> Option { + self.to_u64().and_then(|x| x.to_u32()) + } + + /// Converts the value of `self` to an `u64`. + #[inline] + fn to_u64(&self) -> Option; + + /// Converts the value of `self` to an `f32`. + #[inline] + fn to_f32(&self) -> Option { + self.to_f64().and_then(|x| x.to_f32()) + } + + /// Converts the value of `self` to an `f64`. + #[inline] + fn to_f64(&self) -> Option { + self.to_i64().and_then(|x| x.to_f64()) + } +} + +macro_rules! impl_to_primitive_int_to_int { + ($SrcT:ty, $DstT:ty, $slf:expr) => ( + { + if size_of::<$SrcT>() <= size_of::<$DstT>() { + Some($slf as $DstT) + } else { + let n = $slf as i64; + let min_value: $DstT = Bounded::min_value(); + let max_value: $DstT = Bounded::max_value(); + if min_value as i64 <= n && n <= max_value as i64 { + Some($slf as $DstT) + } else { + None + } + } + } + ) +} + +macro_rules! impl_to_primitive_int_to_uint { + ($SrcT:ty, $DstT:ty, $slf:expr) => ( + { + let zero: $SrcT = 0; + let max_value: $DstT = Bounded::max_value(); + if zero <= $slf && $slf as u64 <= max_value as u64 { + Some($slf as $DstT) + } else { + None + } + } + ) +} + +macro_rules! impl_to_primitive_int { + ($T:ty) => ( + impl ToPrimitive for $T { + #[inline] + fn to_isize(&self) -> Option { impl_to_primitive_int_to_int!($T, isize, *self) } + #[inline] + fn to_i8(&self) -> Option { impl_to_primitive_int_to_int!($T, i8, *self) } + #[inline] + fn to_i16(&self) -> Option { impl_to_primitive_int_to_int!($T, i16, *self) } + #[inline] + fn to_i32(&self) -> Option { impl_to_primitive_int_to_int!($T, i32, *self) } + #[inline] + fn to_i64(&self) -> Option { impl_to_primitive_int_to_int!($T, i64, *self) } + + #[inline] + fn to_usize(&self) -> Option { impl_to_primitive_int_to_uint!($T, usize, *self) } + #[inline] + fn to_u8(&self) -> Option { impl_to_primitive_int_to_uint!($T, u8, *self) } + #[inline] + fn to_u16(&self) -> Option { impl_to_primitive_int_to_uint!($T, u16, *self) } + #[inline] + fn to_u32(&self) -> Option { impl_to_primitive_int_to_uint!($T, u32, *self) } + #[inline] + fn to_u64(&self) -> Option { impl_to_primitive_int_to_uint!($T, u64, *self) } + + #[inline] + fn to_f32(&self) -> Option { Some(*self as f32) } + #[inline] + fn to_f64(&self) -> Option { Some(*self as f64) } + } + ) +} + +impl_to_primitive_int! { isize } +impl_to_primitive_int! { i8 } +impl_to_primitive_int! { i16 } +impl_to_primitive_int! { i32 } +impl_to_primitive_int! { i64 } + +macro_rules! impl_to_primitive_uint_to_int { + ($DstT:ty, $slf:expr) => ( + { + let max_value: $DstT = Bounded::max_value(); + if $slf as u64 <= max_value as u64 { + Some($slf as $DstT) + } else { + None + } + } + ) +} + +macro_rules! impl_to_primitive_uint_to_uint { + ($SrcT:ty, $DstT:ty, $slf:expr) => ( + { + if size_of::<$SrcT>() <= size_of::<$DstT>() { + Some($slf as $DstT) + } else { + let zero: $SrcT = 0; + let max_value: $DstT = Bounded::max_value(); + if zero <= $slf && $slf as u64 <= max_value as u64 { + Some($slf as $DstT) + } else { + None + } + } + } + ) +} + +macro_rules! impl_to_primitive_uint { + ($T:ty) => ( + impl ToPrimitive for $T { + #[inline] + fn to_isize(&self) -> Option { impl_to_primitive_uint_to_int!(isize, *self) } + #[inline] + fn to_i8(&self) -> Option { impl_to_primitive_uint_to_int!(i8, *self) } + #[inline] + fn to_i16(&self) -> Option { impl_to_primitive_uint_to_int!(i16, *self) } + #[inline] + fn to_i32(&self) -> Option { impl_to_primitive_uint_to_int!(i32, *self) } + #[inline] + fn to_i64(&self) -> Option { impl_to_primitive_uint_to_int!(i64, *self) } + + #[inline] + fn to_usize(&self) -> Option { + impl_to_primitive_uint_to_uint!($T, usize, *self) + } + #[inline] + fn to_u8(&self) -> Option { impl_to_primitive_uint_to_uint!($T, u8, *self) } + #[inline] + fn to_u16(&self) -> Option { impl_to_primitive_uint_to_uint!($T, u16, *self) } + #[inline] + fn to_u32(&self) -> Option { impl_to_primitive_uint_to_uint!($T, u32, *self) } + #[inline] + fn to_u64(&self) -> Option { impl_to_primitive_uint_to_uint!($T, u64, *self) } + + #[inline] + fn to_f32(&self) -> Option { Some(*self as f32) } + #[inline] + fn to_f64(&self) -> Option { Some(*self as f64) } + } + ) +} + +impl_to_primitive_uint! { usize } +impl_to_primitive_uint! { u8 } +impl_to_primitive_uint! { u16 } +impl_to_primitive_uint! { u32 } +impl_to_primitive_uint! { u64 } + +macro_rules! impl_to_primitive_float_to_float { + ($SrcT:ident, $DstT:ident, $slf:expr) => ( + if size_of::<$SrcT>() <= size_of::<$DstT>() { + Some($slf as $DstT) + } else { + let n = $slf as f64; + let max_value: $SrcT = ::std::$SrcT::MAX; + if -max_value as f64 <= n && n <= max_value as f64 { + Some($slf as $DstT) + } else { + None + } + } + ) +} + +macro_rules! impl_to_primitive_float { + ($T:ident) => ( + impl ToPrimitive for $T { + #[inline] + fn to_isize(&self) -> Option { Some(*self as isize) } + #[inline] + fn to_i8(&self) -> Option { Some(*self as i8) } + #[inline] + fn to_i16(&self) -> Option { Some(*self as i16) } + #[inline] + fn to_i32(&self) -> Option { Some(*self as i32) } + #[inline] + fn to_i64(&self) -> Option { Some(*self as i64) } + + #[inline] + fn to_usize(&self) -> Option { Some(*self as usize) } + #[inline] + fn to_u8(&self) -> Option { Some(*self as u8) } + #[inline] + fn to_u16(&self) -> Option { Some(*self as u16) } + #[inline] + fn to_u32(&self) -> Option { Some(*self as u32) } + #[inline] + fn to_u64(&self) -> Option { Some(*self as u64) } + + #[inline] + fn to_f32(&self) -> Option { impl_to_primitive_float_to_float!($T, f32, *self) } + #[inline] + fn to_f64(&self) -> Option { impl_to_primitive_float_to_float!($T, f64, *self) } + } + ) +} + +impl_to_primitive_float! { f32 } +impl_to_primitive_float! { f64 } + +pub trait FromPrimitive: Sized { + #[inline] + fn from_isize(n: isize) -> Option { + FromPrimitive::from_i64(n as i64) + } + + #[inline] + fn from_i8(n: i8) -> Option { + FromPrimitive::from_i64(n as i64) + } + + #[inline] + fn from_i16(n: i16) -> Option { + FromPrimitive::from_i64(n as i64) + } + + #[inline] + fn from_i32(n: i32) -> Option { + FromPrimitive::from_i64(n as i64) + } + + fn from_i64(n: i64) -> Option; + + #[inline] + fn from_usize(n: usize) -> Option { + FromPrimitive::from_u64(n as u64) + } + + #[inline] + fn from_u8(n: u8) -> Option { + FromPrimitive::from_u64(n as u64) + } + + #[inline] + fn from_u16(n: u16) -> Option { + FromPrimitive::from_u64(n as u64) + } + + #[inline] + fn from_u32(n: u32) -> Option { + FromPrimitive::from_u64(n as u64) + } + + fn from_u64(n: u64) -> Option; + + #[inline] + fn from_f32(n: f32) -> Option { + FromPrimitive::from_f64(n as f64) + } + + #[inline] + fn from_f64(n: f64) -> Option { + FromPrimitive::from_i64(n as i64) + } +} + +macro_rules! impl_from_primitive { + ($T:ty, $to_ty:ident) => ( + impl FromPrimitive for $T { + #[inline] fn from_i8(n: i8) -> Option<$T> { n.$to_ty() } + #[inline] fn from_i16(n: i16) -> Option<$T> { n.$to_ty() } + #[inline] fn from_i32(n: i32) -> Option<$T> { n.$to_ty() } + #[inline] fn from_i64(n: i64) -> Option<$T> { n.$to_ty() } + + #[inline] fn from_u8(n: u8) -> Option<$T> { n.$to_ty() } + #[inline] fn from_u16(n: u16) -> Option<$T> { n.$to_ty() } + #[inline] fn from_u32(n: u32) -> Option<$T> { n.$to_ty() } + #[inline] fn from_u64(n: u64) -> Option<$T> { n.$to_ty() } + + #[inline] fn from_f32(n: f32) -> Option<$T> { n.$to_ty() } + #[inline] fn from_f64(n: f64) -> Option<$T> { n.$to_ty() } + } + ) +} + +impl_from_primitive! { isize, to_isize } +impl_from_primitive! { i8, to_i8 } +impl_from_primitive! { i16, to_i16 } +impl_from_primitive! { i32, to_i32 } +impl_from_primitive! { i64, to_i64 } +impl_from_primitive! { usize, to_usize } +impl_from_primitive! { u8, to_u8 } +impl_from_primitive! { u16, to_u16 } +impl_from_primitive! { u32, to_u32 } +impl_from_primitive! { u64, to_u64 } +impl_from_primitive! { f32, to_f32 } +impl_from_primitive! { f64, to_f64 } diff --git a/serde/src/de/impls.rs b/serde/src/de/impls.rs index 4db468a8..dbf0042b 100644 --- a/serde/src/de/impls.rs +++ b/serde/src/de/impls.rs @@ -20,8 +20,6 @@ use std::rc::Rc; use std::str; use std::sync::Arc; -use num::FromPrimitive; - #[cfg(feature = "nightly")] use core::nonzero::{NonZero, Zeroable}; @@ -39,6 +37,7 @@ use de::{ VariantVisitor, Visitor, }; +use de::from_primitive::FromPrimitive; /////////////////////////////////////////////////////////////////////////////// @@ -1086,88 +1085,3 @@ impl Deserialize for IgnoredAny { deserializer.deserialize_ignored_any(IgnoredAnyVisitor) } } - - -/////////////////////////////////////////////////////////////////////////////// - -#[cfg(feature = "num-bigint")] -impl Deserialize for ::num::bigint::BigInt { - fn deserialize(deserializer: &mut D) -> Result - where D: Deserializer, - { - use ::num::Num; - use ::num::bigint::BigInt; - - struct BigIntVisitor; - - impl Visitor for BigIntVisitor { - type Value = BigInt; - - fn visit_str(&mut self, s: &str) -> Result - where E: Error, - { - match BigInt::from_str_radix(s, 10) { - Ok(v) => Ok(v), - Err(err) => Err(Error::invalid_value(&err.to_string())), - } - } - } - - deserializer.deserialize(BigIntVisitor) - } -} - -#[cfg(feature = "num-bigint")] -impl Deserialize for ::num::bigint::BigUint { - fn deserialize(deserializer: &mut D) -> Result - where D: Deserializer, - { - use ::num::Num; - use ::num::bigint::BigUint; - - struct BigUintVisitor; - - impl Visitor for BigUintVisitor { - type Value = ::num::bigint::BigUint; - - fn visit_str(&mut self, s: &str) -> Result - where E: Error, - { - match BigUint::from_str_radix(s, 10) { - Ok(v) => Ok(v), - Err(err) => Err(Error::invalid_value(&err.to_string())), - } - } - } - - deserializer.deserialize(BigUintVisitor) - } -} - -#[cfg(feature = "num-complex")] -impl Deserialize for ::num::complex::Complex - where T: Deserialize + Clone + ::num::Num -{ - fn deserialize(deserializer: &mut D) -> Result - where D: Deserializer, - { - let (re, im) = try!(Deserialize::deserialize(deserializer)); - Ok(::num::complex::Complex::new(re, im)) - } -} - -#[cfg(feature = "num-rational")] -impl Deserialize for ::num::rational::Ratio - where T: Deserialize + Clone + ::num::Integer + PartialOrd -{ - fn deserialize(deserializer: &mut D) -> Result - where D: Deserializer, - { - let (numer, denom) = try!(Deserialize::deserialize(deserializer)); - if denom == ::num::Zero::zero() { - Err(Error::invalid_value("denominator is zero")) - } else { - Ok(::num::rational::Ratio::new_raw(numer, denom)) - } - } -} diff --git a/serde/src/de/mod.rs b/serde/src/de/mod.rs index 142502b7..a69f2701 100644 --- a/serde/src/de/mod.rs +++ b/serde/src/de/mod.rs @@ -4,6 +4,7 @@ use std::error; pub mod impls; pub mod value; +mod from_primitive; /////////////////////////////////////////////////////////////////////////////// diff --git a/serde/src/lib.rs b/serde/src/lib.rs index ed6c5592..b00fdc17 100644 --- a/serde/src/lib.rs +++ b/serde/src/lib.rs @@ -17,8 +17,6 @@ #![deny(missing_docs)] -extern crate num; - #[cfg(feature = "nightly")] extern crate collections; diff --git a/serde/src/ser/impls.rs b/serde/src/ser/impls.rs index ac604936..e7a2e601 100644 --- a/serde/src/ser/impls.rs +++ b/serde/src/ser/impls.rs @@ -764,37 +764,3 @@ impl Serialize for NonZero where T: Serialize + Zeroable { (**self).serialize(serializer) } } - -/////////////////////////////////////////////////////////////////////////////// - -#[cfg(feature = "num-bigint")] -impl Serialize for ::num::bigint::BigInt { - fn serialize(&self, serializer: &mut S) -> Result<(), S::Error> where S: Serializer { - self.to_str_radix(10).serialize(serializer) - } -} - -#[cfg(feature = "num-bigint")] -impl Serialize for ::num::bigint::BigUint { - fn serialize(&self, serializer: &mut S) -> Result<(), S::Error> where S: Serializer { - self.to_str_radix(10).serialize(serializer) - } -} - -#[cfg(feature = "num-complex")] -impl Serialize for ::num::complex::Complex - where T: Serialize + Clone + ::num::Num -{ - fn serialize(&self, serializer: &mut S) -> Result<(), S::Error> where S: Serializer { - (&self.re, &self.im).serialize(serializer) - } -} - -#[cfg(feature = "num-rational")] -impl Serialize for ::num::rational::Ratio - where T: Serialize + Clone + ::num::Integer + PartialOrd -{ - fn serialize(&self, serializer: &mut S) -> Result<(), S::Error> where S: Serializer { - (self.numer(), self.denom()).serialize(serializer) - } -} diff --git a/serde_macros/Cargo.toml b/serde_macros/Cargo.toml index 23e15383..58c0105e 100644 --- a/serde_macros/Cargo.toml +++ b/serde_macros/Cargo.toml @@ -21,9 +21,8 @@ serde_codegen = { version = "^0.6.14", path = "../serde_codegen", default-featur [dev-dependencies] compiletest_rs = "^0.0.11" -num = "^0.1.27" rustc-serialize = "^0.3.16" -serde = { version = "^0.6.14", path = "../serde", features = ["num-impls"] } +serde = { version = "^0.6.14", path = "../serde" } [[test]] name = "test" diff --git a/serde_macros/benches/bench.rs b/serde_macros/benches/bench.rs index 3f607229..089bc852 100644 --- a/serde_macros/benches/bench.rs +++ b/serde_macros/benches/bench.rs @@ -2,7 +2,6 @@ #![cfg_attr(feature = "clippy", plugin(clippy))] #![plugin(serde_macros)] -extern crate num; extern crate rustc_serialize; extern crate serde; extern crate test; diff --git a/serde_macros/tests/test.rs b/serde_macros/tests/test.rs index 2f2af797..f2e785a5 100644 --- a/serde_macros/tests/test.rs +++ b/serde_macros/tests/test.rs @@ -1,7 +1,6 @@ #![feature(test, custom_attribute, custom_derive, plugin)] #![plugin(serde_macros)] -extern crate num; extern crate serde; extern crate test; diff --git a/serde_tests/Cargo.toml b/serde_tests/Cargo.toml index 51ee24f8..200a6d51 100644 --- a/serde_tests/Cargo.toml +++ b/serde_tests/Cargo.toml @@ -19,9 +19,8 @@ syntex_syntax = { version = "^0.29.0" } serde_codegen = { version = "^0.6.14", path = "../serde_codegen", features = ["with-syntex"] } [dev-dependencies] -num = "^0.1.26" rustc-serialize = "^0.3.16" -serde = { version = "*", path = "../serde", features = ["num-impls"] } +serde = { version = "*", path = "../serde" } syntex = "^0.29.0" [dependencies] diff --git a/serde_tests/benches/bench.rs b/serde_tests/benches/bench.rs index db86c6a6..d83323ae 100644 --- a/serde_tests/benches/bench.rs +++ b/serde_tests/benches/bench.rs @@ -2,7 +2,6 @@ #![cfg_attr(feature = "nightly", feature(plugin))] #![cfg_attr(feature = "nightly", plugin(clippy))] -extern crate num; extern crate rustc_serialize; extern crate serde; extern crate test; diff --git a/serde_tests/tests/test.rs b/serde_tests/tests/test.rs index 7fefeebc..689a28bc 100644 --- a/serde_tests/tests/test.rs +++ b/serde_tests/tests/test.rs @@ -1,7 +1,6 @@ #![cfg_attr(feature = "nightly", feature(plugin))] #![cfg_attr(feature = "nightly", plugin(clippy))] -extern crate num; extern crate serde; include!(concat!(env!("OUT_DIR"), "/test.rs")); diff --git a/serde_tests/tests/test_de.rs b/serde_tests/tests/test_de.rs index 88f6a9ad..082d627d 100644 --- a/serde_tests/tests/test_de.rs +++ b/serde_tests/tests/test_de.rs @@ -2,11 +2,6 @@ use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet}; use std::net; use std::path::PathBuf; -use num::FromPrimitive; -use num::bigint::{BigInt, BigUint}; -use num::complex::Complex; -use num::rational::Ratio; - use serde::de::{Deserializer, Visitor}; use token::{ @@ -583,35 +578,6 @@ declare_tests! { "1.2.3.4:1234".parse::().unwrap() => vec![Token::Str("1.2.3.4:1234")], "[::1]:1234".parse::().unwrap() => vec![Token::Str("[::1]:1234")], } - test_num_bigint { - BigInt::from_i64(123).unwrap() => vec![Token::Str("123")], - BigInt::from_i64(-123).unwrap() => vec![Token::Str("-123")], - } - test_num_biguint { - BigUint::from_i64(123).unwrap() => vec![Token::Str("123")], - } - test_num_complex { - Complex::new(1, 2) => vec![ - Token::SeqStart(Some(2)), - Token::SeqSep, - Token::I32(1), - - Token::SeqSep, - Token::I32(2), - Token::SeqEnd, - ], - } - test_num_ratio { - Ratio::new(1, 2) => vec![ - Token::SeqStart(Some(2)), - Token::SeqSep, - Token::I32(1), - - Token::SeqSep, - Token::I32(2), - Token::SeqEnd, - ], - } test_path_buf { PathBuf::from("/usr/local/lib") => vec![ Token::String("/usr/local/lib".to_owned()), diff --git a/serde_tests/tests/test_ser.rs b/serde_tests/tests/test_ser.rs index bf9bd1ea..2edd7c17 100644 --- a/serde_tests/tests/test_ser.rs +++ b/serde_tests/tests/test_ser.rs @@ -3,11 +3,6 @@ use std::net; use std::path::{Path, PathBuf}; use std::str; -use num::FromPrimitive; -use num::bigint::{BigInt, BigUint}; -use num::complex::Complex; -use num::rational::Ratio; - use token::{self, Token}; ////////////////////////////////////////////////////////////////////////// @@ -278,35 +273,6 @@ declare_ser_tests! { "1.2.3.4:1234".parse::().unwrap() => &[Token::Str("1.2.3.4:1234")], "[::1]:1234".parse::().unwrap() => &[Token::Str("[::1]:1234")], } - test_num_bigint { - BigInt::from_i64(123).unwrap() => &[Token::Str("123")], - BigInt::from_i64(-123).unwrap() => &[Token::Str("-123")], - } - test_num_biguint { - BigUint::from_i64(123).unwrap() => &[Token::Str("123")], - } - test_num_complex { - Complex::new(1, 2) => &[ - Token::SeqStart(Some(2)), - Token::SeqSep, - Token::I32(1), - - Token::SeqSep, - Token::I32(2), - Token::SeqEnd, - ], - } - test_num_ratio { - Ratio::new(1, 2) => &[ - Token::SeqStart(Some(2)), - Token::SeqSep, - Token::I32(1), - - Token::SeqSep, - Token::I32(2), - Token::SeqEnd, - ], - } test_path { Path::new("/usr/local/lib") => &[ Token::Str("/usr/local/lib"),