Using diesel with shared crate

Hi all

I'm writing a web app in Rust using Yew for frontend. I have a bunch of models in a shared crate that are being sent between the frontend and the backend.

Now I want to also store these models in a database. I started looking at diesel but it requires structs to be annotated with #[derive(Insertable)] and other similar macros.

If I add these to my shared crate then I'm introducing a dependency on diesel on the front end (not sure if this will even work at all!).

Is there any way around that? Ideally I'd like to only define my models once and use them both on frontend and backend.

Try cfg_attr:

#[cfg_attr(feature = "server", derive(Debug))]
struct Model {}

fn main() {
    let x = Model {};
}

Thanks!

It should probably also require the dependency on diesel to be optional and only enabled for the server feature.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.