Refactor project structure

This commit is contained in:
Zhang Junyang
2024-02-27 16:40:16 +08:00
committed by Tate, Hongliang Tian
parent bd878dd1c9
commit e3c227ae06
474 changed files with 77 additions and 77 deletions

View File

@ -0,0 +1,57 @@
// SPDX-License-Identifier: MPL-2.0
//! This crate defines two attribute macros `controlled` and `uncontrolled`.
//! This two macros are attached to functions or static variables to enable crate level access control.
//! To use these two macros, a crate must at first registers a tool named `component_access_control`,
//! because controlled used tool attribute internally.
//!
//! Below is a simple usage example.
//! ```rust
//! // crate-level tool registration
//! #![feature(register_tool)]
//! #![register_tool(component_access_control)]
//!
//! #[macro_use]
//! extern crate controlled; // import this crate
//!
//! #[controlled]
//! pub static FOO: usize = 0;
//!
//! #[uncontrolled]
//! pub fn bar() {}
//! ```
use quote::quote;
#[proc_macro_attribute]
pub fn controlled(
attr: proc_macro::TokenStream,
item: proc_macro::TokenStream,
) -> proc_macro::TokenStream {
let attr = attr.to_string();
if attr.len() != 0 {
panic!("controlled cannot accept inner tokens.")
}
let mut tokens: proc_macro::TokenStream = quote!(
#[component_access_control::controlled]
)
.into();
tokens.extend(item);
tokens
}
#[proc_macro_attribute]
pub fn uncontrolled(
attr: proc_macro::TokenStream,
item: proc_macro::TokenStream,
) -> proc_macro::TokenStream {
let attr = attr.to_string();
if attr.len() != 0 {
panic!("uncontrolled cannot accept inner tokens.")
}
let mut tokens: proc_macro::TokenStream = quote!(
#[component_access_control::uncontrolled]
)
.into();
tokens.extend(item);
tokens
}