5 points

If you don’t mind a quick review:

Another thing worth noting is that it’s as if the proc macro literally injects a bit of source code in-line where you call derive. This means that if you are going to refer to any structs/crates/modules etc… it makes things a lot easier to refer to them via their full path.

I since that someone doesn’t know about putting their impls in a:

const _: () = {
}

Also, using quote!{} instead of quote!() will make your indentation life easier.

anyhow instead of thiserror in your API is…

Otherwise, good, if very basic, write-up.

PS: How dare you post this to Reddit you Fediverse traitor 😉

permalink
report
reply
2 points

Oh nooooo I’ve been discovered posting to reddit! 😯 We need to really post more rust content here, there’s barely anything.

Yeah I just used anyhow instead of thiserror as that’s what I’m using on divedb.

I’m not sure about the impl thing, care to elaborate?

permalink
report
parent
reply
2 points

I’m not sure about the impl thing, care to elaborate?

See this serde-derive code.

Basically, you’re wrapping your impl in a dummy const, so your impl lives in its own lexical scope.

You can set attributes on that scope, define consts/statics, import stuff that will not interfere with anything outside the generated code…etc.

So, just add your use lines. You can allow unused imports on the scope too, no conditional imports needed to avoid warnings. You don’t have to worry about anything 😉

permalink
report
parent
reply

Rust Programming

!rust@lemmy.ml

Create post

Community stats

  • 145

    Monthly active users

  • 204

    Posts

  • 631

    Comments