From df7ba4f2d0b5ef3138b0060b5091cabd19ac4767 Mon Sep 17 00:00:00 2001 From: bluss Date: Wed, 21 Nov 2018 21:58:27 +0100 Subject: [PATCH] API: remove rustc-serialize crate feature This is now finally dead, it's obsolete (please use serde instead). --- Cargo.toml | 3 +- README.rst | 5 -- serialization-tests/Cargo.toml | 5 +- serialization-tests/tests/serialize.rs | 66 ------------------ src/array_serialize.rs | 97 -------------------------- src/arraytraits.rs | 2 +- src/lib.rs | 7 -- 7 files changed, 3 insertions(+), 182 deletions(-) delete mode 100644 src/array_serialize.rs diff --git a/Cargo.toml b/Cargo.toml index 372092d9a..4c296dc4c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -29,7 +29,6 @@ test = true [dependencies] num-traits = "0.2" num-complex = "0.2" -rustc-serialize = { version = "0.3.20", optional = true } itertools = { version = "0.7.0", default-features = false } # Use via the `blas` crate feature! @@ -58,7 +57,7 @@ test-blas-openblas-sys = ["blas"] test = ["test-blas-openblas-sys"] # This feature is used for docs -docs = ["rustc-serialize", "serde-1"] +docs = ["serde-1"] [profile.release] [profile.bench] diff --git a/README.rst b/README.rst index ba3735345..3e8959a9a 100644 --- a/README.rst +++ b/README.rst @@ -47,11 +47,6 @@ Crate Feature Flags The following crate feature flags are available. They are configured in your `Cargo.toml`. -- ``rustc-serialize`` - - - Optional, compatible with Rust stable - - Enables serialization support for rustc-serialize 0.3 - - ``serde-1`` - Optional, compatible with Rust stable diff --git a/serialization-tests/Cargo.toml b/serialization-tests/Cargo.toml index 2e650959c..9c46600e1 100644 --- a/serialization-tests/Cargo.toml +++ b/serialization-tests/Cargo.toml @@ -8,14 +8,11 @@ publish = false test = false [dependencies] -ndarray = { path = "../", features = ["serde-1", "rustc-serialize"] } +ndarray = { path = "../", features = ["serde-1"] } [features] default = ["ron"] -[dev-dependencies.rustc-serialize] -version = "0.3.21" - [dev-dependencies.serde] version = "1.0" diff --git a/serialization-tests/tests/serialize.rs b/serialization-tests/tests/serialize.rs index 93cf8ce9b..d0a2f3b79 100644 --- a/serialization-tests/tests/serialize.rs +++ b/serialization-tests/tests/serialize.rs @@ -1,5 +1,3 @@ -extern crate rustc_serialize as serialize; - extern crate ndarray; extern crate serde; @@ -11,73 +9,9 @@ extern crate rmp_serde; #[cfg(feature = "ron")] extern crate ron; -use serialize::json; - use ndarray::{arr0, arr1, arr2, s, RcArray, RcArray1, RcArray2, ArrayD, IxDyn}; -#[test] -fn serial_many_dim() -{ - { - let a = arr0::(2.72); - let serial = json::encode(&a).unwrap(); - println!("Encode {:?} => {:?}", a, serial); - let res = json::decode::>(&serial); - println!("{:?}", res); - assert_eq!(a, res.unwrap()); - } - - { - let a = arr1::(&[2.72, 1., 2.]); - let serial = json::encode(&a).unwrap(); - println!("Encode {:?} => {:?}", a, serial); - let res = json::decode::>(&serial); - println!("{:?}", res); - assert_eq!(a, res.unwrap()); - } - - { - let a = arr2(&[[3., 1., 2.2], [3.1, 4., 7.]]); - let serial = json::encode(&a).unwrap(); - println!("Encode {:?} => {:?}", a, serial); - let res = json::decode::>(&serial); - println!("{:?}", res); - assert_eq!(a, res.unwrap()); - let text = r##"{"v":1,"dim":[2,3],"data":[3,1,2.2,3.1,4,7]}"##; - let b = json::decode::>(text); - assert_eq!(a, b.unwrap()); - } - - - { - // Test a sliced array. - let mut a = RcArray::linspace(0., 31., 32).reshape((2, 2, 2, 4)); - a.slice_collapse(s![..;-1, .., .., ..2]); - let serial = json::encode(&a).unwrap(); - println!("Encode {:?} => {:?}", a, serial); - let res = json::decode::>(&serial); - println!("{:?}", res); - assert_eq!(a, res.unwrap()); - } -} - -#[test] -fn serial_wrong_count() -{ - // one element too few - let text = r##"{"v":1,"dim":[2,3],"data":[3,1,2.2,3.1,4]}"##; - let arr = json::decode::>(text); - println!("{:?}", arr); - assert!(arr.is_err()); - - // future version - let text = r##"{"v":200,"dim":[2,3],"data":[3,1,2.2,3.1,4,7]}"##; - let arr = json::decode::>(text); - println!("{:?}", arr); - assert!(arr.is_err()); -} - #[test] fn serial_many_dim_serde() { diff --git a/src/array_serialize.rs b/src/array_serialize.rs deleted file mode 100644 index f10fd0842..000000000 --- a/src/array_serialize.rs +++ /dev/null @@ -1,97 +0,0 @@ -// Copyright 2014-2016 bluss and ndarray developers. -// -// 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. - -use serialize::{Encodable, Encoder, Decodable, Decoder}; -use super::arraytraits::ARRAY_FORMAT_VERSION; -use super::dimension; - -use imp_prelude::*; - -/// **Requires crate feature `"rustc-serialize"`** -impl Encodable for Dim - where I: Encodable, -{ - fn encode(&self, s: &mut E) -> Result<(), E::Error> { - self.ix().encode(s) - } -} - -/// **Requires crate feature `"rustc-serialize"`** -impl Decodable for Dim - where I: Decodable, -{ - fn decode(d: &mut E) -> Result { - I::decode(d).map(Dim::new) - } -} - -/// **Requires crate feature `"rustc-serialize"`** -impl Encodable for ArrayBase - where A: Encodable, - D: Dimension + Encodable, - S: Data -{ - fn encode(&self, s: &mut E) -> Result<(), E::Error> { - s.emit_struct("Array", 3, |e| { - try!(e.emit_struct_field("v", 0, |e| ARRAY_FORMAT_VERSION.encode(e))); - // FIXME: Write self.dim as a slice (self.shape) - // The problem is decoding it. - try!(e.emit_struct_field("dim", 1, |e| self.dim.encode(e))); - try!(e.emit_struct_field("data", 2, |e| { - let sz = self.dim.size(); - e.emit_seq(sz, |e| { - for (i, elt) in self.iter().enumerate() { - try!(e.emit_seq_elt(i, |e| elt.encode(e))) - } - Ok(()) - }) - })); - Ok(()) - }) - } -} - -/// **Requires crate feature `"rustc-serialize"`** -impl Decodable for ArrayBase - where A: Decodable, - D: Dimension + Decodable, - S: DataOwned -{ - fn decode(d: &mut E) -> Result { - d.read_struct("Array", 3, |d| { - let version: u8 = try!(d.read_struct_field("v", 0, Decodable::decode)); - if version > ARRAY_FORMAT_VERSION { - return Err(d.error("unknown array version")) - } - let dim: D = try!(d.read_struct_field("dim", 1, |d| { - Decodable::decode(d) - })); - - let elements = try!( - d.read_struct_field("data", 2, |d| { - d.read_seq(|d, len| { - let dim_size = dimension::size_of_shape_checked(&dim) - .map_err(|_| d.error("overflow calculating array size"))?; - if len != dim_size { - Err(d.error("data and dimension must match in size")) - } else { - let mut elements = Vec::with_capacity(len); - for i in 0..len { - elements.push(try!(d.read_seq_elt::(i, Decodable::decode))) - } - Ok(elements) - } - }) - })); - unsafe { - Ok(ArrayBase::from_shape_vec_unchecked(dim, elements)) - } - }) - } -} - diff --git a/src/arraytraits.rs b/src/arraytraits.rs index ce86ea35d..cc5cf64e8 100644 --- a/src/arraytraits.rs +++ b/src/arraytraits.rs @@ -208,7 +208,7 @@ unsafe impl Send for ArrayBase where S: Send + Data, D: Send { } -#[cfg(any(feature = "rustc-serialize", feature = "serde"))] +#[cfg(any(feature = "serde"))] // Use version number so we can add a packed format later. pub const ARRAY_FORMAT_VERSION: u8 = 1u8; diff --git a/src/lib.rs b/src/lib.rs index e764b8182..f0bd8bbd9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -65,9 +65,6 @@ //! The following crate feature flags are available. They are configured in your //! `Cargo.toml`. //! -//! - `rustc-serialize` -//! - Optional, compatible with Rust stable -//! - Enables serialization support for rustc-serialize 0.3 //! - `serde-1` //! - Optional, compatible with Rust stable //! - Enables serialization support for serde 1.0 @@ -89,8 +86,6 @@ #[cfg(feature = "serde-1")] extern crate serde; -#[cfg(feature = "rustc-serialize")] -extern crate rustc_serialize as serialize; #[cfg(feature="blas")] extern crate cblas_sys; @@ -143,8 +138,6 @@ mod aliases; mod arraytraits; #[cfg(feature = "serde-1")] mod array_serde; -#[cfg(feature = "rustc-serialize")] -mod array_serialize; mod arrayformat; mod data_traits;