1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
use rustc_span::symbol::Symbol;

#[derive(Clone, Debug, Eq, PartialEq)]
pub enum TargetFeature {
    Extension(Symbol),
    Capability(rspirv::spirv::Capability),
}

impl std::str::FromStr for TargetFeature {
    type Err = String;

    fn from_str(input: &str) -> Result<Self, Self::Err> {
        const EXT_PREFIX: &str = "ext:";

        if let Some(input) = input.strip_prefix(EXT_PREFIX) {
            Ok(Self::Extension(Symbol::intern(input)))
        } else {
            Ok(Self::Capability(input.parse().map_err(|_err| {
                format!("Invalid Capability: `{input}`")
            })?))
        }
    }
}