Skip to content

Commit

Permalink
Auto merge of #2201 - matklad:serialized-dep, r=alexcrichton
Browse files Browse the repository at this point in the history
This hides `SerializedDependency` from general public, as requested [here](#1434 (comment)). It also hides `SerializedManifest` which was (wrongly?) exposed.

This is required for #2196. I want to move in small steps this time, hence the separate PR.

Technically this break backwards compatibility, because `SerializedDependency` and `SerializedManifest` were public (`SerializedPackage` was private however). Are such changes allowed in cargo?
  • Loading branch information
bors committed Dec 8, 2015
2 parents 488e8d8 + a42422d commit fcff230
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 28 deletions.
31 changes: 17 additions & 14 deletions src/cargo/core/dependency.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use semver::VersionReq;
use rustc_serialize::{Encoder, Encodable};

use core::{SourceId, Summary, PackageId};
use std::rc::Rc;
Expand Down Expand Up @@ -30,6 +31,22 @@ pub struct Dependency {
inner: Rc<DependencyInner>,
}


#[derive(RustcEncodable)]
struct SerializedDependency {
name: String,
req: String
}

impl Encodable for Dependency {
fn encode<S: Encoder>(&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,
Expand Down Expand Up @@ -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()
}
}
}
13 changes: 5 additions & 8 deletions src/cargo/core/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -44,11 +43,11 @@ pub struct ManifestMetadata {
pub documentation: Option<String>, // url
}

#[derive(PartialEq,Clone,RustcEncodable)]
pub struct SerializedManifest {
#[derive(RustcEncodable)]
struct SerializedManifest<'a> {
name: String,
version: String,
dependencies: Vec<SerializedDependency>,
dependencies: &'a [Dependency],
targets: Vec<Target>,
}

Expand All @@ -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)
}
Expand Down
9 changes: 3 additions & 6 deletions src/cargo/core/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -24,10 +23,10 @@ pub struct Package {
}

#[derive(RustcEncodable)]
struct SerializedPackage {
struct SerializedPackage<'a> {
name: String,
version: String,
dependencies: Vec<SerializedDependency>,
dependencies: &'a [Dependency],
targets: Vec<Target>,
manifest_path: String,
}
Expand All @@ -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)
Expand Down

0 comments on commit fcff230

Please sign in to comment.