1use std::path::PathBuf;
23use crate::regex_set::RegexSet;
45/// Trait used to turn [`crate::BindgenOptions`] fields into CLI args.
6pub(super) trait AsArgs {
7fn as_args(&self, args: &mut Vec<String>, flag: &str);
8}
910/// If the `bool` is `true`, `flag` is pushed into `args`.
11///
12/// be careful about the truth value of the field as some options, like `--no-layout-tests`, are
13/// actually negations of the fields.
14impl AsArgs for bool {
15fn as_args(&self, args: &mut Vec<String>, flag: &str) {
16if *self {
17 args.push(flag.to_string());
18 }
19 }
20}
2122/// Iterate over all the items of the `RegexSet` and push `flag` followed by the item into `args`
23/// for each item.
24impl AsArgs for RegexSet {
25fn as_args(&self, args: &mut Vec<String>, flag: &str) {
26for item in self.get_items() {
27 args.extend_from_slice(&[flag.to_owned(), item.clone().into()]);
28 }
29 }
30}
3132/// If the `Option` is `Some(value)`, push `flag` followed by `value`.
33impl AsArgs for Option<String> {
34fn as_args(&self, args: &mut Vec<String>, flag: &str) {
35if let Some(string) = self {
36 args.extend_from_slice(&[flag.to_owned(), string.clone()]);
37 }
38 }
39}
4041/// If the `Option` is `Some(path)`, push `flag` followed by the [`std::path::Path::display`]
42/// representation of `path`.
43impl AsArgs for Option<PathBuf> {
44fn as_args(&self, args: &mut Vec<String>, flag: &str) {
45if let Some(path) = self {
46 args.extend_from_slice(&[
47 flag.to_owned(),
48 path.display().to_string(),
49 ]);
50 }
51 }
52}