From 7a7c5fb2adf9665a85c215f05c4d2e7ceebf7a6a Mon Sep 17 00:00:00 2001 From: gifnksm Date: Thu, 13 Nov 2014 20:54:42 +0900 Subject: [PATCH] Implements `Encodable` and `Decodable` Fixes #27 --- src/bigint.rs | 6 +++--- src/complex.rs | 2 +- src/lib.rs | 1 + src/rational.rs | 2 +- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/bigint.rs b/src/bigint.rs index e523790..3ba6ce7 100644 --- a/src/bigint.rs +++ b/src/bigint.rs @@ -112,7 +112,7 @@ pub mod BigDigit { /// /// A `BigUint`-typed value `BigUint { data: vec!(a, b, c) }` represents a number /// `(a + b * BigDigit::BASE + c * BigDigit::BASE^2)`. -#[deriving(Clone)] +#[deriving(Clone, Encodable, Decodable)] pub struct BigUint { data: Vec } @@ -843,7 +843,7 @@ fn get_radix_base(radix: uint) -> (DoubleBigDigit, uint) { } /// A Sign is a `BigInt`'s composing element. -#[deriving(PartialEq, PartialOrd, Eq, Ord, Clone, Show)] +#[deriving(PartialEq, PartialOrd, Eq, Ord, Clone, Show, Encodable, Decodable)] pub enum Sign { Minus, NoSign, Plus } impl Neg for Sign { @@ -859,7 +859,7 @@ impl Neg for Sign { } /// A big signed integer type. -#[deriving(Clone)] +#[deriving(Clone, Encodable, Decodable)] pub struct BigInt { sign: Sign, data: BigUint diff --git a/src/complex.rs b/src/complex.rs index 370dba9..0d40b5f 100644 --- a/src/complex.rs +++ b/src/complex.rs @@ -18,7 +18,7 @@ use std::num::{Zero, One}; // probably doesn't map to C's _Complex correctly. /// A complex number in Cartesian form. -#[deriving(PartialEq, Clone, Hash)] +#[deriving(PartialEq, Clone, Hash, Encodable, Decodable)] pub struct Complex { /// Real portion of the complex number pub re: T, diff --git a/src/lib.rs b/src/lib.rs index 53d1e81..f386d4b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -58,6 +58,7 @@ #![allow(deprecated)] // from_str_radix extern crate rand; +extern crate serialize; pub use bigint::{BigInt, BigUint}; pub use rational::{Rational, BigRational}; diff --git a/src/rational.rs b/src/rational.rs index 1be7066..2c3fbc3 100644 --- a/src/rational.rs +++ b/src/rational.rs @@ -21,7 +21,7 @@ use std::num::{Zero, One, FromStrRadix}; use bigint::{BigInt, BigUint, Sign, Plus, Minus}; /// Represents the ratio between 2 numbers. -#[deriving(Clone, Hash)] +#[deriving(Clone, Hash, Encodable, Decodable)] #[allow(missing_docs)] pub struct Ratio { numer: T,