microsoft/qdk
Publicmirrored from https://github.com/microsoft/qdkAvailable
compiler/qsc/src/target.rs
43lines · modecode
| 1 | // Copyright (c) Microsoft Corporation. |
| 2 | // Licensed under the MIT License. |
| 3 | |
| 4 | use std::str::FromStr; |
| 5 | |
| 6 | use qsc_frontend::compile::RuntimeCapabilityFlags; |
| 7 | |
| 8 | #[derive(Clone, Copy, Debug, PartialEq)] |
| 9 | pub enum Profile { |
| 10 | Unrestricted, |
| 11 | Base, |
| 12 | } |
| 13 | |
| 14 | impl Profile { |
| 15 | #[must_use] |
| 16 | pub fn to_str(&self) -> &'static str { |
| 17 | match self { |
| 18 | Self::Unrestricted => "Unrestricted", |
| 19 | Self::Base => "Base", |
| 20 | } |
| 21 | } |
| 22 | } |
| 23 | |
| 24 | impl From<Profile> for RuntimeCapabilityFlags { |
| 25 | fn from(value: Profile) -> Self { |
| 26 | match value { |
| 27 | Profile::Unrestricted => Self::all(), |
| 28 | Profile::Base => Self::empty(), |
| 29 | } |
| 30 | } |
| 31 | } |
| 32 | |
| 33 | impl FromStr for Profile { |
| 34 | type Err = (); |
| 35 | |
| 36 | fn from_str(s: &str) -> Result<Self, Self::Err> { |
| 37 | match s { |
| 38 | "Unrestricted" | "unrestricted" => Ok(Self::Unrestricted), |
| 39 | "Base" | "base" => Ok(Self::Base), |
| 40 | _ => Err(()), |
| 41 | } |
| 42 | } |
| 43 | } |
| 44 | |