sc-lint 0.8.5

Top-level CLI composition root for the sc-lint tool family.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
//! Consumer test selectors (ADR-020 decision 7).
//!
//! `[tool.sc-lint.test]` is exactly one of two forms per file: the existing
//! `[[tool.sc-lint.test]]` row array, where each row is a command selector
//! named after the row, or a table with an optional `default` and
//! `selectors.<name>` entries (a `command` argv or a `group` of selector names,
//! plus `env`, `cwd`, `platforms` and `after_all`). Table entries iterate in
//! sorted name order (`toml::Table` is sorted); group members keep their listed
//! order; rows keep declaration order.

use std::collections::BTreeMap;
use std::collections::BTreeSet;
use std::ffi::OsStr;
use std::path::Path;
use std::path::PathBuf;

use serde_json::Value;
use serde_json::json;

use crate::CliError;
use crate::config::CONSUMER_SELECTOR_ALL;
use crate::config::consumer_profile_error;
use crate::profile_plan::ConsumerProfileStep;
use crate::profile_plan::Platform;
use crate::scheduler::ProfileCode;
use crate::workflow::Lane;
use crate::workflow::StepPlan;

const TEST_PROFILE: &str = "test";
const TABLE_KEYS: [&str; 2] = ["default", "selectors"];
const SELECTOR_KEYS: [&str; 7] = [
    "command",
    "group",
    "env",
    "env_paths",
    "cwd",
    "platforms",
    "after_all",
];
const GROUP_FORBIDDEN_KEYS: [&str; 4] = ["env", "env_paths", "cwd", "platforms"];

/// A non-blank selector name.
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
pub(crate) struct SelectorName(String);

impl SelectorName {
    /// Parses a selector name; blank names are rejected.
    pub(crate) fn parse(value: String) -> Option<Self> {
        (!value.trim().is_empty()).then_some(Self(value))
    }

    pub(crate) fn as_str(&self) -> &str {
        &self.0
    }
}

/// What a selector runs.
#[derive(Debug, Clone, PartialEq, Eq)]
pub(crate) enum SelectorBody {
    /// One command argv.
    Command(Vec<String>),
    /// Other selectors, in listed order.
    Group(Vec<SelectorName>),
}

/// One declared test selector.
#[derive(Debug, Clone, PartialEq, Eq)]
pub(crate) struct TestSelector {
    name: SelectorName,
    body: SelectorBody,
    env: BTreeMap<String, String>,
    env_path_keys: Vec<String>,
    cwd: Option<PathBuf>,
    platforms: Vec<Platform>,
    after_all: bool,
}

impl TestSelector {
    pub(crate) fn name(&self) -> &str {
        self.name.as_str()
    }

    /// Whether this selector runs on `host` (no `platforms` means every host).
    pub(crate) fn runs_on(&self, host: Platform) -> bool {
        self.platforms.is_empty() || self.platforms.contains(&host)
    }

    /// The `data.steps[]` row of a selector skipped on `host`.
    pub(crate) fn skipped_row(&self, host: Platform) -> Value {
        json!({
            "name": self.name(),
            "status": "skipped",
            "reason": "platform_mismatch",
            "host": host.as_str(),
            "platforms": self.platform_names(),
        })
    }

    /// The executable step of a command selector with `args` appended.
    pub(crate) fn step_plan(&self, args: &[String]) -> StepPlan {
        let SelectorBody::Command(argv) = &self.body else {
            unreachable!("only command selectors are expanded into steps")
        };
        let (program, rest) = argv.split_first().expect("validated non-empty command");
        let mut plan = StepPlan::new(
            self.name(),
            TEST_PROFILE,
            Lane::for_program(OsStr::new(program)),
            program,
            rest.iter().chain(args),
        )
        .with_after_all(self.after_all);
        for (key, value) in &self.env {
            plan = plan.with_env(key, value);
        }
        match &self.cwd {
            Some(cwd) => plan.with_cwd(cwd.clone()),
            None => plan,
        }
    }

    fn platform_names(&self) -> Vec<&'static str> {
        self.platforms
            .iter()
            .map(|platform| platform.as_str())
            .collect()
    }

    fn list_json(&self) -> Value {
        let mut row = json!({
            "name": self.name(),
            "kind": match self.body {
                SelectorBody::Command(_) => "command",
                SelectorBody::Group(_) => "group",
            },
            "platforms": self.platform_names(),
            "cwd": self.cwd.as_ref().map(|cwd| cwd.display().to_string()),
            "env_keys": self.env.keys().filter(|key| !self.env_path_keys.contains(key)).collect::<Vec<_>>(),
            "env_path_keys": self.env_path_keys,
            "after_all": self.after_all,
        });
        let (key, value) = match &self.body {
            SelectorBody::Command(argv) => ("command", json!(argv)),
            SelectorBody::Group(members) => (
                "group",
                json!(members.iter().map(SelectorName::as_str).collect::<Vec<_>>()),
            ),
        };
        if let Some(fields) = row.as_object_mut() {
            fields.insert(key.to_string(), value);
        }
        row
    }
}

/// The validated `[tool.sc-lint.test]` declaration of one config file.
#[derive(Debug, Clone, PartialEq, Eq)]
pub(crate) struct TestSelectors {
    entries: Vec<TestSelector>,
    default: Option<SelectorName>,
    legacy: bool,
    source: PathBuf,
}

/// What `sc-lint test` was asked to do.
#[derive(Debug, Clone, PartialEq, Eq)]
pub(crate) struct TestRequest {
    selector: Option<String>,
    args: Vec<String>,
    list: bool,
}

impl TestRequest {
    pub(crate) const fn new(selector: Option<String>, args: Vec<String>, list: bool) -> Self {
        Self {
            selector,
            args,
            list,
        }
    }

    pub(crate) fn selector(&self) -> Option<&str> {
        self.selector.as_deref()
    }

    pub(crate) fn args(&self) -> &[String] {
        &self.args
    }

    pub(crate) const fn list(&self) -> bool {
        self.list
    }

    /// A bare `sc-lint test`.
    #[cfg(test)]
    pub(crate) const fn all() -> Self {
        Self::new(None, Vec::new(), false)
    }

    /// `sc-lint test <name>`.
    #[cfg(test)]
    pub(crate) fn named(name: &str) -> Self {
        Self::new(Some(name.to_string()), Vec::new(), false)
    }
}

impl TestSelectors {
    /// Normalizes `[[tool.sc-lint.test]]` rows to command selectors in
    /// declaration order.
    pub(crate) fn from_rows(steps: Vec<ConsumerProfileStep>, source: PathBuf) -> Self {
        let entries = steps
            .into_iter()
            .map(|step| TestSelector {
                name: SelectorName(step.name().to_string()),
                body: SelectorBody::Command(step.command().to_vec()),
                env: BTreeMap::new(),
                env_path_keys: Vec::new(),
                cwd: None,
                platforms: Vec::new(),
                after_all: step.after_all(),
            })
            .collect();
        Self {
            entries,
            default: None,
            legacy: true,
            source,
        }
    }

    /// Validates the table form; the first error wins, in this order: unknown
    /// keys, per-selector shape, undeclared names, group cycles.
    #[expect(
        clippy::result_large_err,
        reason = "Selector validation returns the shared top-level CliError contract."
    )]
    pub(crate) fn parse_table(table: &toml::Table, source: &Path) -> Result<Self, CliError> {
        let malformed = |message: String| consumer_profile_error(source, TEST_PROFILE, message);
        let raw = raw_selectors(table, &malformed)?;
        let mut entries = Vec::with_capacity(raw.len());
        for (name, fields) in raw {
            entries.push(parse_selector(name, fields, source, &malformed)?);
        }
        let default = match table.get("default") {
            None => None,
            Some(toml::Value::String(name)) => Some(SelectorName(name.clone())),
            Some(_) => {
                return Err(malformed(
                    "`tool.sc-lint.test.default` must be a selector name string".to_string(),
                ));
            }
        };
        let selectors = Self {
            entries,
            default,
            legacy: false,
            source: source.to_path_buf(),
        };
        selectors.check_references()?;
        selectors.check_cycles()?;
        Ok(selectors)
    }

    /// The command selectors `requested` runs, in order, each at most once.
    ///
    /// Rows form: `None` or `all` selects every row. Table form: `None`
    /// selects `default`; `all` is an ordinary name.
    #[expect(
        clippy::result_large_err,
        reason = "Selector resolution returns the shared top-level CliError contract."
    )]
    pub(crate) fn expand(&self, requested: Option<&str>) -> Result<Vec<&TestSelector>, CliError> {
        if self.runs_every_row(requested) {
            return Ok(self.entries.iter().collect());
        }
        let selector = self.resolve(requested)?;
        let mut expanded = Vec::new();
        self.push_expanded(selector, &mut expanded, &mut BTreeSet::new());
        Ok(expanded)
    }

    /// Rows form: `None` or `all` selects every row rather than one selector.
    fn runs_every_row(&self, requested: Option<&str>) -> bool {
        self.legacy && requested.is_none_or(|name| name == CONSUMER_SELECTOR_ALL)
    }

    /// The one selector `requested` names (table form: `None` is `default`),
    /// or the `test.unknown_selector` error.
    #[expect(
        clippy::result_large_err,
        reason = "Selector resolution returns the shared top-level CliError contract."
    )]
    fn resolve(&self, requested: Option<&str>) -> Result<&TestSelector, CliError> {
        let name = match (requested, &self.default) {
            (Some(name), _) => name,
            (None, Some(default)) => default.as_str(),
            (None, None) => {
                return Err(self.unknown(
                    format!(
                        "no selector was named and {} declares no default",
                        self.source.display()
                    ),
                    None,
                ));
            }
        };
        self.find(name).ok_or_else(|| {
            self.unknown(
                format!(
                    "selector '{name}' is not declared in {}",
                    self.source.display()
                ),
                Some(name),
            )
        })
    }

    /// Rejects forwarded arguments unless `request` names a command selector.
    #[expect(
        clippy::result_large_err,
        reason = "Usage errors use the shared top-level CliError contract."
    )]
    pub(crate) fn check_forwarded_args(&self, request: &TestRequest) -> Result<(), CliError> {
        if request.args().is_empty() {
            return Ok(());
        }
        let requested = request.selector();
        if self.runs_every_row(requested) {
            return Err(CliError::usage(format!(
                "selector '{CONSUMER_SELECTOR_ALL}' runs every [[tool.sc-lint.test]] row and does not accept forwarded arguments"
            ))
            .with_suggested_action("name a command selector to forward arguments"));
        }
        let selector = self.resolve(requested)?;
        if matches!(selector.body, SelectorBody::Group(_)) {
            return Err(CliError::usage(format!(
                "group selector '{}' does not accept forwarded arguments",
                selector.name()
            ))
            .with_suggested_action("name a command selector to forward arguments"));
        }
        Ok(())
    }

    /// The selector name a run reports: the requested name, else `default`
    /// (table form) or `all` (rows form).
    pub(crate) fn selected_name(&self, requested: Option<&str>) -> String {
        requested
            .or_else(|| self.default.as_ref().map(SelectorName::as_str))
            .unwrap_or(CONSUMER_SELECTOR_ALL)
            .to_string()
    }

    /// `data` of `sc-lint test --list`.
    pub(crate) fn list_json(&self) -> Value {
        json!({
            "status": "pass",
            "profile": TEST_PROFILE,
            "default": self.default.as_ref().map(SelectorName::as_str),
            "selectors": self.entries.iter().map(TestSelector::list_json).collect::<Vec<_>>(),
        })
    }

    fn find(&self, name: &str) -> Option<&TestSelector> {
        self.entries.iter().find(|selector| selector.name() == name)
    }

    fn names(&self) -> Vec<&str> {
        self.entries.iter().map(TestSelector::name).collect()
    }

    fn push_expanded<'a>(
        &'a self,
        selector: &'a TestSelector,
        expanded: &mut Vec<&'a TestSelector>,
        seen: &mut BTreeSet<&'a str>,
    ) {
        match &selector.body {
            SelectorBody::Command(_) => {
                if seen.insert(selector.name()) {
                    expanded.push(selector);
                }
            }
            SelectorBody::Group(members) => {
                for member in members {
                    if let Some(next) = self.find(member.as_str()) {
                        self.push_expanded(next, expanded, seen);
                    }
                }
            }
        }
    }

    fn unknown(&self, cause: String, selector: Option<&str>) -> CliError {
        ProfileCode::UnknownSelector
            .config_error(cause, &self.source)
            .with_detail("selector", json!(selector))
            .with_detail("available", json!(self.names()))
    }

    #[expect(
        clippy::result_large_err,
        reason = "Selector validation returns the shared top-level CliError contract."
    )]
    fn check_references(&self) -> Result<(), CliError> {
        let path = self.source.display();
        for selector in &self.entries {
            let SelectorBody::Group(members) = &selector.body else {
                continue;
            };
            if let Some(member) = members
                .iter()
                .find(|member| self.find(member.as_str()).is_none())
            {
                return Err(self.unknown(
                    format!(
                        "selector '{}' listed by group '{}' is not declared in {path}",
                        member.as_str(),
                        selector.name()
                    ),
                    Some(member.as_str()),
                ));
            }
        }
        match &self.default {
            Some(default) if self.find(default.as_str()).is_none() => Err(self.unknown(
                format!(
                    "default names selector '{}', which is not declared in {path}",
                    default.as_str()
                ),
                Some(default.as_str()),
            )),
            _ => Ok(()),
        }
    }

    /// Depth-first over selectors in sorted order, members in listed order;
    /// the first cycle found is reported from its first repeated selector.
    #[expect(
        clippy::result_large_err,
        reason = "Selector validation returns the shared top-level CliError contract."
    )]
    fn check_cycles(&self) -> Result<(), CliError> {
        let mut finished = BTreeSet::new();
        for selector in &self.entries {
            if let Some(cycle) = self.find_cycle(selector, &mut Vec::new(), &mut finished) {
                return Err(ProfileCode::GroupCycle.config_error(
                    format!(
                        "selector group cycle: {} in {}",
                        cycle.join(" -> "),
                        self.source.display()
                    ),
                    &self.source,
                ));
            }
        }
        Ok(())
    }

    fn find_cycle<'a>(
        &'a self,
        selector: &'a TestSelector,
        path: &mut Vec<&'a str>,
        finished: &mut BTreeSet<&'a str>,
    ) -> Option<Vec<&'a str>> {
        if let Some(start) = path.iter().position(|name| *name == selector.name()) {
            let mut cycle = path[start..].to_vec();
            cycle.push(selector.name());
            return Some(cycle);
        }
        if finished.contains(selector.name()) {
            return None;
        }
        path.push(selector.name());
        if let SelectorBody::Group(members) = &selector.body {
            for member in members {
                let next = self.find(member.as_str())?;
                if let Some(cycle) = self.find_cycle(next, path, finished) {
                    return Some(cycle);
                }
            }
        }
        path.pop();
        finished.insert(selector.name());
        None
    }
}

/// Step 1 of table validation: exact keys of the table and of every selector.
#[expect(
    clippy::result_large_err,
    reason = "Selector validation returns the shared top-level CliError contract."
)]
fn raw_selectors<'a>(
    table: &'a toml::Table,
    malformed: &dyn Fn(String) -> CliError,
) -> Result<Vec<(&'a String, &'a toml::Table)>, CliError> {
    if let Some(key) = table.keys().find(|key| !TABLE_KEYS.contains(&key.as_str())) {
        return Err(malformed(format!(
            "`tool.sc-lint.test` has unknown key `{key}`; use `default` and `selectors`"
        )));
    }
    let selectors = match table.get("selectors") {
        Some(toml::Value::Table(selectors)) if !selectors.is_empty() => selectors,
        None | Some(toml::Value::Table(_)) => {
            return Err(malformed(
                "consumer test profile must contain at least one selector".to_string(),
            ));
        }
        Some(_) => {
            return Err(malformed(
                "`tool.sc-lint.test.selectors` must be a table of selectors".to_string(),
            ));
        }
    };
    let mut raw = Vec::with_capacity(selectors.len());
    for (name, value) in selectors {
        let toml::Value::Table(fields) = value else {
            return Err(malformed(format!("selector `{name}` must be a table")));
        };
        if let Some(key) = fields
            .keys()
            .find(|key| !SELECTOR_KEYS.contains(&key.as_str()))
        {
            return Err(malformed(format!(
                "selector `{name}` has unknown key `{key}`; selectors accept {}",
                SELECTOR_KEYS.join(", ")
            )));
        }
        raw.push((name, fields));
    }
    Ok(raw)
}

/// Step 2 of table validation for one selector.
#[expect(
    clippy::result_large_err,
    reason = "Selector validation returns the shared top-level CliError contract."
)]
fn parse_selector(
    name: &str,
    fields: &toml::Table,
    source: &Path,
    malformed: &dyn Fn(String) -> CliError,
) -> Result<TestSelector, CliError> {
    let selector_name = SelectorName::parse(name.to_string())
        .ok_or_else(|| malformed("selector names must not be blank".to_string()))?;
    let body = match (fields.get("command"), fields.get("group")) {
        (Some(command), None) => SelectorBody::Command(parse_command(name, command, malformed)?),
        (None, Some(group)) => SelectorBody::Group(parse_group(name, group, fields, malformed)?),
        _ => {
            return Err(malformed(format!(
                "selector `{name}` must declare exactly one of `command` or `group`"
            )));
        }
    };
    let subject = format!("selector `{name}`");
    let (env, env_path_keys) =
        crate::step_paths::execution_env(fields.get("env"), fields.get("env_paths"), source)
            .map_err(|error| malformed(error.message(&subject)))?;
    let cwd = crate::step_exec::parse_cwd(fields.get("cwd"))
        .map_err(|error| malformed(error.message(&subject)))?;
    let platforms = parse_platforms(name, fields.get("platforms"), malformed)?;
    let after_all = parse_after_all(name, &body, fields.get("after_all"), source)?;
    Ok(TestSelector {
        name: selector_name,
        body,
        env,
        env_path_keys: env_path_keys.unwrap_or_default(),
        cwd,
        platforms,
        after_all,
    })
}

#[expect(
    clippy::result_large_err,
    reason = "Selector validation returns the shared top-level CliError contract."
)]
fn parse_command(
    name: &str,
    value: &toml::Value,
    malformed: &dyn Fn(String) -> CliError,
) -> Result<Vec<String>, CliError> {
    let argv = string_array(value).ok_or_else(|| {
        malformed(format!(
            "selector `{name}` command must be an array of strings"
        ))
    })?;
    if argv.is_empty() {
        return Err(malformed(format!("selector `{name}` has an empty command")));
    }
    if argv.iter().any(|argument| argument.trim().is_empty()) {
        return Err(malformed(format!(
            "selector `{name}` has a blank command argument"
        )));
    }
    Ok(argv)
}

#[expect(
    clippy::result_large_err,
    reason = "Selector validation returns the shared top-level CliError contract."
)]
fn parse_group(
    name: &str,
    value: &toml::Value,
    fields: &toml::Table,
    malformed: &dyn Fn(String) -> CliError,
) -> Result<Vec<SelectorName>, CliError> {
    let members = string_array(value).ok_or_else(|| {
        malformed(format!(
            "selector `{name}` group must be an array of selector names"
        ))
    })?;
    if members.is_empty() {
        return Err(malformed(format!(
            "group selector `{name}` lists no selectors"
        )));
    }
    if let Some(key) = GROUP_FORBIDDEN_KEYS
        .iter()
        .find(|key| fields.contains_key(**key))
    {
        return Err(malformed(format!(
            "group selector `{name}` declares `{key}`; only command selectors accept env, env_paths, cwd and platforms"
        )));
    }
    members
        .into_iter()
        .map(|member| {
            SelectorName::parse(member)
                .ok_or_else(|| malformed(format!("group selector `{name}` lists a blank name")))
        })
        .collect()
}

#[expect(
    clippy::result_large_err,
    reason = "Selector validation returns the shared top-level CliError contract."
)]
fn parse_platforms(
    name: &str,
    value: Option<&toml::Value>,
    malformed: &dyn Fn(String) -> CliError,
) -> Result<Vec<Platform>, CliError> {
    let Some(value) = value else {
        return Ok(Vec::new());
    };
    let invalid = || {
        malformed(format!(
            "selector `{name}` platforms must list only linux, macos or windows"
        ))
    };
    let names = string_array(value).ok_or_else(invalid)?;
    names
        .iter()
        .map(|platform| Platform::parse(platform).ok_or_else(invalid))
        .collect()
}

#[expect(
    clippy::result_large_err,
    reason = "Selector validation returns the shared top-level CliError contract."
)]
fn parse_after_all(
    name: &str,
    body: &SelectorBody,
    value: Option<&toml::Value>,
    source: &Path,
) -> Result<bool, CliError> {
    let path = source.display();
    match (body, value) {
        (_, None) => Ok(false),
        (SelectorBody::Group(_), Some(_)) => Err(ProfileCode::InvalidAfterAll.config_error(
            format!("group selector '{name}' in {path} declares after_all"),
            source,
        )),
        (SelectorBody::Command(_), Some(toml::Value::Boolean(after_all))) => Ok(*after_all),
        (SelectorBody::Command(_), Some(_)) => Err(ProfileCode::InvalidAfterAll.config_error(
            format!("selector '{name}' in {path} declares a non-boolean after_all"),
            source,
        )),
    }
}

/// The elements of an array of strings, `None` for any other shape.
fn string_array(value: &toml::Value) -> Option<Vec<String>> {
    value
        .as_array()?
        .iter()
        .map(|item| item.as_str().map(str::to_string))
        .collect()
}