21
submitted 1 year ago by cetra3@lemmy.ml to c/rust@lemmy.ml
you are viewing a single comment's thread
view the rest of the comments
[-] RunAwayFrog@sh.itjust.works 2 points 1 year ago

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 😉

[-] cetra3@lemmy.ml 1 points 1 year ago

Oh wow I'm getting flashbacks to IIFE in js! Makes sense

this post was submitted on 23 Jul 2023
21 points (100.0% liked)

Rust Programming

8150 readers
13 users here now

founded 5 years ago
MODERATORS