Skip to content

Latest commit

 

History

History
90 lines (67 loc) · 2.5 KB

proc-macro-crate.md

File metadata and controls

90 lines (67 loc) · 2.5 KB
category description crev
Macros
$crate for proc macros (prefer shim macros per review notes!)
neutral

proc-macro-crate

$crate for proc macros

Prefer shim macros where possible (they're less brittle / more portable - thank dtolnay for the suggestion!):

#[doc(hidden)] pub use impl_crate::my_macro_impl;

#[macro_export] macro_rules! my_macro {
    ($($args:tt)*) => {
        $crate::my_macro_impl!{$crate $($args)*}
    };
}
#[proc_macro] pub fn my_macro_impl(input: TokenStream) -> TokenStream {
    let mut tokens = input.into_iter();
    let my_crate = tokens.next().unwrap();
    ...
}

Where not possible, consider hardcoding a fallback for non-cargo build environments such as Bazel instead of panicing (since proc_macro_crate relies on parsing Cargo.toml):

let my_crate = proc_macro_crate::crate_name("my-crate").unwrap_or("my_crate".to_string());

Audit

version thoroughness understanding rating Notes
0.1.4 medium medium positive Diff
0.1.3 medium medium positive Diff
0.1.2 medium medium positive Diff
0.1.1 medium medium positive Diff
0.1.0 medium medium positive Full review

0.1.4

  • Version bumps, typos, formatting
  • Start searching [target.*.dependencies] too

0.1.3

Dropped 'static lifetime requirements

0.1.2

  • Added syn, proc-macro2 deps
  • Sanitized "-" to "_"

0.1.1

Minor metadata tweaks

0.1.0

file rating notes
src/lib.rs ✔️
.cargo-ok ✔️
.gitignore ✔️
.travis.yml ✔️ MSRV: stable
Cargo.toml ✔️ Apache-2.0/MIT
Cargo.toml.orig ✔️ Apache-2.0/MIT
README.md ✔️ Apache-2.0 OR MIT
Other Rating Notes
unsafe ✔️ None
fs ✔️ Opens %CARGO_MANIFEST_DIR%\Cargo.toml for read only
io ✔️ Bulk parsing outsourced to toml crate
docs ✔️ Straightforward
tests ✔️