modular_bitfield_impl/
lib.rs

1#![recursion_limit = "256"]
2#![forbid(unsafe_code)]
3#![warn(clippy::pedantic, rust_2018_idioms)]
4
5#[macro_use]
6mod errors;
7mod bitfield;
8mod bitfield_specifier;
9mod define_specifiers;
10
11use proc_macro::TokenStream;
12
13/// Generates the `B1`, `B2`, ..., `B128` bitfield specifiers.
14///
15/// Only of use witihn the `modular_bitfield` crate itself.
16#[proc_macro]
17pub fn define_specifiers(input: TokenStream) -> TokenStream {
18    define_specifiers::generate(input.into()).into()
19}
20
21#[proc_macro_attribute]
22pub fn bitfield(args: TokenStream, input: TokenStream) -> TokenStream {
23    bitfield::analyse_and_expand(args.into(), input.into()).into()
24}
25
26#[proc_macro_derive(Specifier, attributes(bits))]
27pub fn specifier(input: TokenStream) -> TokenStream {
28    bitfield_specifier::generate(input.into()).into()
29}
30
31#[cfg(coverage)]
32#[test]
33fn ui_code_coverage() {
34    use runtime_macros::{emulate_attributelike_macro_expansion, emulate_derive_macro_expansion};
35    use std::fs::File;
36
37    let mut run_success = true;
38    for entry in glob::glob("../tests/ui/**/*.rs").unwrap() {
39        let entry = entry.unwrap();
40        run_success &= emulate_attributelike_macro_expansion(
41            File::open(entry.as_path()).unwrap(),
42            &[("bitfield", bitfield::analyse_and_expand)],
43        )
44        .is_ok();
45        run_success &= emulate_derive_macro_expansion(
46            File::open(entry.as_path()).unwrap(),
47            &[("Specifier", bitfield_specifier::generate)],
48        )
49        .is_ok();
50    }
51
52    assert!(run_success);
53}