mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
Change #[privatize] into #[derive(DenyPublicFields)]
This commit is contained in:
parent
19c645ff68
commit
8bcf36b9a5
16 changed files with 69 additions and 65 deletions
14
components/deny_public_fields/Cargo.toml
Normal file
14
components/deny_public_fields/Cargo.toml
Normal file
|
@ -0,0 +1,14 @@
|
|||
[package]
|
||||
name = "deny_public_fields"
|
||||
version = "0.0.1"
|
||||
authors = ["The Servo Project Developers"]
|
||||
license = "MPL-2.0"
|
||||
publish = false
|
||||
|
||||
[lib]
|
||||
path = "lib.rs"
|
||||
proc-macro = true
|
||||
|
||||
[dependencies]
|
||||
syn = "0.10"
|
||||
synstructure = "0.4"
|
26
components/deny_public_fields/lib.rs
Normal file
26
components/deny_public_fields/lib.rs
Normal file
|
@ -0,0 +1,26 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
extern crate proc_macro;
|
||||
extern crate syn;
|
||||
extern crate synstructure;
|
||||
|
||||
#[proc_macro_derive(DenyPublicFields)]
|
||||
pub fn expand_token_stream(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
|
||||
expand_string(&input.to_string()).parse().unwrap()
|
||||
}
|
||||
|
||||
fn expand_string(input: &str) -> String {
|
||||
let type_ = syn::parse_macro_input(input).unwrap();
|
||||
|
||||
let style = synstructure::BindStyle::Ref.into();
|
||||
synstructure::each_field(&type_, &style, |binding| {
|
||||
if binding.field.vis != syn::Visibility::Inherited {
|
||||
panic!("Field {} should not be public", binding.ident);
|
||||
}
|
||||
"".to_owned()
|
||||
});
|
||||
|
||||
"".to_owned()
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue