microsoft/qdk

Public

mirrored fromhttps://github.com/microsoft/qdkAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
alex/reexports-fixes

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

compiler/qsc_data_structures/src/language_features.rs

50lines · modecode

1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4use bitflags::bitflags;
5use serde::Deserialize;
6
7#[derive(Deserialize, Clone, Debug, PartialOrd, Ord, PartialEq, Eq, Copy)]
8pub struct LanguageFeatures(u8);
9
10bitflags! {
11 impl LanguageFeatures: u8 {
12 const V2PreviewSyntax = 0b1;
13 }
14}
15
16impl LanguageFeatures {
17 pub fn merge(&mut self, other: impl Into<LanguageFeatures>) {
18 self.0 |= other.into().0;
19 }
20}
21
22impl Default for LanguageFeatures {
23 fn default() -> Self {
24 LanguageFeatures::empty()
25 }
26}
27
28impl<I> FromIterator<I> for LanguageFeatures
29where
30 I: AsRef<str>,
31{
32 fn from_iter<T: IntoIterator<Item = I>>(iter: T) -> Self {
33 iter.into_iter().fold(LanguageFeatures::empty(), |acc, x| {
34 acc | match x.as_ref() {
35 "v2-preview-syntax" => LanguageFeatures::V2PreviewSyntax,
36 _ => LanguageFeatures::empty(),
37 }
38 })
39 }
40}
41
42impl From<LanguageFeatures> for Vec<String> {
43 fn from(features: LanguageFeatures) -> Self {
44 let mut result = Vec::new();
45 if features.contains(LanguageFeatures::V2PreviewSyntax) {
46 result.push("v2-preview-syntax".to_string());
47 }
48 result
49 }
50}
51