this post was submitted on 23 Jul 2023
22 points (100.0% liked)
Rust Programming
7734 readers
3 users here now
founded 5 years ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
If you don't mind a quick review:
I since that someone doesn't know about putting their
impl
s in a:Also, using
quote!{}
instead ofquote!()
will make your indentation life easier.anyhow
instead ofthiserror
in your API is...Otherwise, good, if very basic, write-up.
PS: How dare you post this to Reddit you Fediverse traitor ๐
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?
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 ๐Oh wow I'm getting flashbacks to IIFE in js! Makes sense