derive-deftly is nearing 1.x - call for review/testing
derive-deftly
, the template-based derive-macro facility for Rust, has been a great success.
It’s coming up to time to declare a stable 1.x version. If you’d like to try it out, and have final comments / observations, now is the time.
Introduction to derive-deftly
Have you ever wished that you could that could write a new derive
macro without having to mess with procedural macros?
You can!
derive-deftly
lets you write a #[derive]
macro, using a template syntax which looks a lot like macro_rules!
:
use derive_deftly::{define_derive_deftly, Deftly};
define_derive_deftly! {
ListVariants:
impl $ttype {
fn list_variants() -> Vec<&'static str> {
vec![ $( stringify!( $vname ) , ) ]
}
}
}
#[derive(Deftly)]
#[derive_deftly(ListVariants)]
enum Enum {
UnitVariant,
StructVariant { a: u8, b: u16 },
TupleVariant(u8, u16),
}
assert_eq!(
Enum::list_variants(),
["UnitVariant", "StructVariant", "TupleVariant"],
);
Status
derive-deftly has a wide range of features, which can be used to easily write sophisticated and reliable derive macros. We’ve been using it in Arti, the Tor Project’s reimplementation of Tor in Rust, and we’ve found it very useful.
There is comprehensive reference documentation, and more discursive User Guide for a more gentle introduction. Naturally, everything is fully tested.
History
derive-deftly started out as a Tor Hackweek project. It used to be called derive-adhoc
. But we renamed it because we found that many of the most interesting use cases were really not very ad-hoc at all.
Over the past months we’ve been ticking off our “1.0 blocker” tickets. We’ve taken the opportunity to improve syntax, terminology, and semantics. We hope we have now made the last breaking changes.
Plans - call for review/testing
In the near future, we plan to declare version 1.0. After 1.x, we intend to make breaking changes very rarely.
So, right now, we’d like last-minute feedback. Are there any wrinkles that need to be sorted out? Please file tickets or MRs on our gitlab. Ideally, anything which might imply breaking changes would be submitted on or before the 13th of August.
In the medium to long term, we have many ideas for how to make derive-deftly even more convenient, and even more powerful. But we are going to proceed cautiously, because we don’t want to introduce bad syntax or bad features, which will require difficult decisions in the future about forward compatibility.