From 53248108ed26c4922279bbdda2d8d3489c19345d Mon Sep 17 00:00:00 2001 From: Seiichi Uchida Date: Wed, 20 Dec 2017 23:47:08 +0900 Subject: [PATCH] Add WorkspaceMember The implementation of WorkspaceMember is almost identical to PackageId in cargo. The difference is that its deserialization is simplified and it does not use Arc internally. --- src/lib.rs | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 23cfac88..52ca3345 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -89,6 +89,7 @@ use std::str::from_utf8; pub use errors::{Error, ErrorKind, Result}; pub use dependency::{Dependency, DependencyKind}; +use serde::de; mod errors; mod dependency; @@ -99,8 +100,7 @@ pub struct Metadata { /// A list of all crates referenced by this crate (and the crate itself) pub packages: Vec, /// A list of all workspace members - #[serde(default)] - pub workspace_members: Vec, + pub workspace_members: Vec, /// Dependencies graph pub resolve: Option, version: usize, @@ -159,6 +159,38 @@ pub struct Target { pub src_path: String, } +#[derive(Clone, Debug)] +/// A workspace member. This is basically identical to `cargo::core::package_id::PackageId`, expect +/// that this does not use `Arc` internally. +pub struct WorkspaceMember { + /// A name of workspace member. + pub name: String, + /// A version of workspace member. + pub version: semver::Version, + /// A source id of workspace member. + pub url: String, +} + +impl<'de> de::Deserialize<'de> for WorkspaceMember { + fn deserialize(d: D) -> std::result::Result + where + D: de::Deserializer<'de>, + { + let string = String::deserialize(d)?; + let mut s = string.splitn(3, ' '); + let name = s.next().unwrap(); + let version = s.next().unwrap(); + let version = semver::Version::parse(&version).map_err(de::Error::custom)?; + let url = &s.next().unwrap(); + let url = &url[1..url.len() - 1]; + Ok(WorkspaceMember { + name: name.to_owned(), + version: version, + url: url.to_owned(), + }) + } +} + /// Obtain metadata only about the root package and don't fetch dependencies /// /// # Parameters