Skip to content

Commit

Permalink
Merge pull request #26 from topecongiro/workspace-member
Browse files Browse the repository at this point in the history
Add WorkspaceMember
  • Loading branch information
oli-obk authored Dec 21, 2017
2 parents db0c5b8 + 5324810 commit 5d230f5
Showing 1 changed file with 34 additions and 2 deletions.
36 changes: 34 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -99,8 +100,7 @@ pub struct Metadata {
/// A list of all crates referenced by this crate (and the crate itself)
pub packages: Vec<Package>,
/// A list of all workspace members
#[serde(default)]
pub workspace_members: Vec<String>,
pub workspace_members: Vec<WorkspaceMember>,
/// Dependencies graph
pub resolve: Option<Resolve>,
version: usize,
Expand Down Expand Up @@ -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: D) -> std::result::Result<WorkspaceMember, D::Error>
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
Expand Down

0 comments on commit 5d230f5

Please sign in to comment.