use std::borrow::Cow;
use std::collections::HashSet;
use crate::Package;
#[allow(single_use_lifetimes)] #[derive(Clone, Debug, Default, Eq, PartialEq)]
pub struct Config<'a> {
pub idents: HashSet<Cow<'a, str>>,
pub name_values: HashSet<(Cow<'a, str>, Cow<'a, str>)>,
}
impl<'a> Config<'a> {
pub fn new() -> Self {
Self::default()
}
pub fn from_package_docs_rs_features(package: &'a Package) -> Self {
Self::new().with_features(package.manifest().docs_rs_features())
}
pub fn with_features<I, T>(mut self, features: I) -> Self
where
I: IntoIterator<Item = T>,
T: Into<Cow<'a, str>>,
{
self.name_values.extend(
features
.into_iter()
.map(|feature| (Cow::from("feature"), feature.into())),
);
self
}
pub fn with_target_arch_os_env(mut self, target: &str) -> Self {
if let Some(platform) = platforms::Platform::find(target) {
let _ = self.name_values.insert((
Cow::from("target_arch"),
Cow::from(platform.target_arch.as_str()),
));
let _ = self.name_values.insert((
Cow::from("target_os"),
Cow::from(platform.target_os.as_str()),
));
let _ = self.name_values.insert((
Cow::from("target_env"),
Cow::from(platform.target_env.as_str()),
));
}
self
}
}