1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-22 15:06:54 -05:00
denoland-deno/ops/attrs.rs
Divy Srivastava d5634164cb
chore: use rustfmt imports_granularity option (#17421)
Closes https://github.com/denoland/deno/issues/2699
Closes https://github.com/denoland/deno/issues/2347

Uses unstable rustfmt features. Since dprint invokes `rustfmt` we do not
need to switch the cargo toolchain to nightly. Do we care about
formatting stability of our codebase across Rust versions? (I don't)
2023-01-14 23:18:58 -05:00

44 lines
1.2 KiB
Rust

// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
use syn::parse::Parse;
use syn::parse::ParseStream;
use syn::punctuated::Punctuated;
use syn::Error;
use syn::Ident;
use syn::Result;
use syn::Token;
#[derive(Copy, Clone, Debug, Default)]
pub struct Attributes {
pub is_unstable: bool,
pub is_v8: bool,
pub must_be_fast: bool,
pub deferred: bool,
pub is_wasm: bool,
}
impl Parse for Attributes {
fn parse(input: ParseStream) -> Result<Self> {
let vars = Punctuated::<Ident, Token![,]>::parse_terminated(input)?;
let vars: Vec<_> = vars.iter().map(Ident::to_string).collect();
let vars: Vec<_> = vars.iter().map(String::as_str).collect();
for var in vars.iter() {
if !["unstable", "v8", "fast", "deferred", "wasm"].contains(var) {
return Err(Error::new(
input.span(),
"invalid attribute, expected one of: unstable, v8, fast, deferred, wasm",
));
}
}
let is_wasm = vars.contains(&"wasm");
Ok(Self {
is_unstable: vars.contains(&"unstable"),
is_v8: vars.contains(&"v8"),
deferred: vars.contains(&"deferred"),
must_be_fast: is_wasm || vars.contains(&"fast"),
is_wasm,
})
}
}