1use std::process::Command;
2
3pub struct Targets(Vec<u8>);
4
5impl Targets {
6 pub fn iter(&self) -> Result<TargetsIter, std::str::Utf8Error> {
7 std::str::from_utf8(&self.0)
8 .map(str::lines)
9 .map(TargetsIter)
10 }
11}
12
13pub struct TargetsIter<'a>(std::str::Lines<'a>);
14
15impl<'a> Iterator for TargetsIter<'a> {
16 type Item = &'a str;
17
18 fn next(&mut self) -> Option<Self::Item> {
19 self.0.next()
20 }
21}
22
23#[doc = include_str!("../examples/targets.rs")]
31pub fn from_cli() -> Result<Targets, std::io::Error> {
33 let output = Command::new("rustc")
34 .arg("--print")
35 .arg("target-list")
36 .output()?;
37
38 Ok(Targets(output.stdout))
39}