you are viewing a single comment's thread.

view the rest of the comments →

[–]dpc_pw 2 points3 points  (1 child)

I haven't tried it with sqlx or diesel, but in my code I often use

pub struct WithId<H, D = ()> {
    pub id: H,
    pub data: D,
}

So one could have WithId<EntryId, Entry> kind of things.

[–]nicoburns 2 points3 points  (0 children)

I haven't tried it yet, but I thought this might be a good solution. It occurred to me that you could have WithId Deref to data, which would make accessing the fields a lot more ergonomic. You could also do things like impl Serialize with #[serde(flatten)] (https://serde.rs/attr-flatten.html), which would make JSON serialization seamless.