From 126ed9c1a41225f16ba3a935a9aacf7645e1a64c Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Mon, 7 Dec 2015 21:37:57 +0300 Subject: [PATCH 1/2] make SerializedManifest private --- src/cargo/core/manifest.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cargo/core/manifest.rs b/src/cargo/core/manifest.rs index 7045ae7507b..4f366ae73fc 100644 --- a/src/cargo/core/manifest.rs +++ b/src/cargo/core/manifest.rs @@ -44,8 +44,8 @@ pub struct ManifestMetadata { pub documentation: Option, // url } -#[derive(PartialEq,Clone,RustcEncodable)] -pub struct SerializedManifest { +#[derive(RustcEncodable)] +struct SerializedManifest { name: String, version: String, dependencies: Vec, From a42422dfd5e75bd7d9edd06660f878270e4d69cb Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Mon, 7 Dec 2015 21:42:15 +0300 Subject: [PATCH 2/2] implement Encodable for Dependency SerializedDependency can be a private implementation detail now. --- src/cargo/core/dependency.rs | 31 +++++++++++++++++-------------- src/cargo/core/manifest.rs | 11 ++++------- src/cargo/core/package.rs | 9 +++------ 3 files changed, 24 insertions(+), 27 deletions(-) diff --git a/src/cargo/core/dependency.rs b/src/cargo/core/dependency.rs index aa74490fef3..1788a1fb78e 100644 --- a/src/cargo/core/dependency.rs +++ b/src/cargo/core/dependency.rs @@ -1,4 +1,5 @@ use semver::VersionReq; +use rustc_serialize::{Encoder, Encodable}; use core::{SourceId, Summary, PackageId}; use std::rc::Rc; @@ -30,6 +31,22 @@ pub struct Dependency { inner: Rc, } + +#[derive(RustcEncodable)] +struct SerializedDependency { + name: String, + req: String +} + +impl Encodable for Dependency { + fn encode(&self, s: &mut S) -> Result<(), S::Error> { + SerializedDependency { + name: self.name().to_string(), + req: self.version_req().to_string() + }.encode(s) + } +} + #[derive(PartialEq, Clone, Debug, Copy)] pub enum Kind { Normal, @@ -219,17 +236,3 @@ impl Dependency { } } -#[derive(PartialEq,Clone,RustcEncodable)] -pub struct SerializedDependency { - name: String, - req: String -} - -impl SerializedDependency { - pub fn from_dependency(dep: &Dependency) -> SerializedDependency { - SerializedDependency { - name: dep.name().to_string(), - req: dep.version_req().to_string() - } - } -} diff --git a/src/cargo/core/manifest.rs b/src/cargo/core/manifest.rs index 4f366ae73fc..28a494eb957 100644 --- a/src/cargo/core/manifest.rs +++ b/src/cargo/core/manifest.rs @@ -3,11 +3,10 @@ use std::fmt; use std::path::{PathBuf, Path}; use semver::Version; -use rustc_serialize::{Encoder,Encodable}; +use rustc_serialize::{Encoder, Encodable}; use core::{Dependency, PackageId, Summary}; use core::package_id::Metadata; -use core::dependency::SerializedDependency; use util::{CargoResult, human}; /// Contains all the information about a package, as loaded from a Cargo.toml. @@ -45,10 +44,10 @@ pub struct ManifestMetadata { } #[derive(RustcEncodable)] -struct SerializedManifest { +struct SerializedManifest<'a> { name: String, version: String, - dependencies: Vec, + dependencies: &'a [Dependency], targets: Vec, } @@ -57,9 +56,7 @@ impl Encodable for Manifest { SerializedManifest { name: self.summary.name().to_string(), version: self.summary.version().to_string(), - dependencies: self.summary.dependencies().iter().map(|d| { - SerializedDependency::from_dependency(d) - }).collect(), + dependencies: self.summary.dependencies(), targets: self.targets.clone(), }.encode(s) } diff --git a/src/cargo/core/package.rs b/src/cargo/core/package.rs index 34855c2f897..c147a224c62 100644 --- a/src/cargo/core/package.rs +++ b/src/cargo/core/package.rs @@ -6,7 +6,6 @@ use semver::Version; use core::{Dependency, Manifest, PackageId, SourceId, Registry, Target, Summary, Metadata}; use ops; -use core::dependency::SerializedDependency; use util::{CargoResult, graph, Config}; use rustc_serialize::{Encoder,Encodable}; use core::source::Source; @@ -24,10 +23,10 @@ pub struct Package { } #[derive(RustcEncodable)] -struct SerializedPackage { +struct SerializedPackage<'a> { name: String, version: String, - dependencies: Vec, + dependencies: &'a [Dependency], targets: Vec, manifest_path: String, } @@ -41,9 +40,7 @@ impl Encodable for Package { SerializedPackage { name: package_id.name().to_string(), version: package_id.version().to_string(), - dependencies: summary.dependencies().iter().map(|d| { - SerializedDependency::from_dependency(d) - }).collect(), + dependencies: summary.dependencies(), targets: manifest.targets().to_vec(), manifest_path: self.manifest_path.display().to_string() }.encode(s)