Debian Codegraph @

.cargo/vendor/bindgen/options/as_args.rs

raw
1 use std::path::PathBuf;
2
3 use crate::RegexSet;
4
5 /// Trait used to turn [`crate::BindgenOptions`] fields into CLI args.
6 pub(super) trait AsArgs {
7 fn as_args(&self, args: &mut Vec<String>, flag: &str);
8 }
9
10 /// 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.
14 impl AsArgs for bool {
15 fn as_args(&self, args: &mut Vec<String>, flag: &str) {
16 if *self {
17 args.push(flag.to_string());
18 }
19 }
20 }
21
22 /// Iterate over all the items of the `RegexSet` and push `flag` followed by the item into `args`
23 /// for each item.
24 impl AsArgs for RegexSet {
25 fn as_args(&self, args: &mut Vec<String>, flag: &str) {
26 for item in self.get_items() {
27 args.extend_from_slice(&[flag.to_owned(), item.clone()]);
28 }
29 }
30 }
31
32 /// If the `Option` is `Some(value)`, push `flag` followed by `value`.
33 impl AsArgs for Option<String> {
34 fn as_args(&self, args: &mut Vec<String>, flag: &str) {
35 if let Some(string) = self {
36 args.extend_from_slice(&[flag.to_owned(), string.clone()]);
37 }
38 }
39 }
40
41 /// If the `Option` is `Some(path)`, push `flag` followed by the [`std::path::Path::display`]
42 /// representation of `path`.
43 impl AsArgs for Option<PathBuf> {
44 fn as_args(&self, args: &mut Vec<String>, flag: &str) {
45 if let Some(path) = self {
46 args.extend_from_slice(&[
47 flag.to_owned(),
48 path.display().to_string(),
49 ]);
50 }
51 }
52 }