use std::{borrow::Cow, path::Path};
use cargo_metadata::{Edition, Package};
type CowStr<'a> = Cow<'a, str>;
pub struct ManualPackage<'a> {
pub name: CowStr<'a>,
pub edition: Option<Edition>,
pub targets: Vec<ManualTarget<'a>>,
}
impl<'a> ManualPackage<'a> {
pub fn new_rl(name: &'a str, src_path: &'a Path) -> Self {
Self {
name: name.into(),
edition: None,
targets: vec![ManualTarget {
kind: vec![String::from("lib")],
src_path: Cow::Borrowed(src_path),
}],
}
}
}
impl From<Package> for ManualPackage<'static> {
fn from(them: Package) -> Self {
Self {
name: them.name.into(),
edition: Some(them.edition),
targets: {
let mut vec = Vec::new();
for target in them.targets {
vec.push(ManualTarget {
kind: target.kind,
src_path: target.src_path.into(),
})
}
vec
},
}
}
}
#[derive(Clone)]
pub struct ManualTarget<'a> {
pub kind: Vec<String>,
pub src_path: Cow<'a, Path>,
}