cargo_toml_builder/types/
feature.rs1use std::default::Default;
2
3use crate::types::Dependency;
4
5#[derive(Default, Debug, Clone, PartialEq)]
7pub struct Feature {
8 pub(crate) label: String,
9 pub(crate) deps: Vec<Dependency>,
10 pub(crate) features: Vec<String>,
11}
12
13impl Feature {
14 pub fn new(label: &str) -> Feature {
16 let mut f = Feature::default();
17 f.label = label.to_string();
18 f
19 }
20
21 pub fn dependency<D: Into<Dependency>>(&mut self, dep: D) -> &mut Self {
23 self.deps.push(dep.into());
24 self
25 }
26
27 pub fn dependencies<D: Into<Dependency>>(&mut self, deps: Vec<D>) -> &mut Self {
29 self.deps = deps.into_iter().map(|d| d.into()).collect();
30 self
31 }
32
33 pub fn feature(&mut self, feature: &str) -> &mut Self {
35 self.features.push(feature.to_string());
36 self
37 }
38
39 pub fn features(&mut self, features: &[String]) -> &mut Self {
43 self.features = features.to_vec();
44 self
45 }
46
47 pub fn build(&self) -> Self {
49 self.clone()
50 }
51}
52
53impl<'a> From<&'a mut Feature> for Feature {
54 fn from(f: &'a mut Feature) -> Feature {
55 f.clone()
56 }
57}
58
59impl<'a> From<&'a str> for Feature {
60 fn from(s: &'a str) -> Feature {
61 Feature {
62 label: s.to_string(),
63 deps: vec![],
64 features: vec![],
65 }
66 }
67}
68