Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider adding #[must_use] to #[table] rows in Rust modules #2261

Open
kazimuth opened this issue Feb 13, 2025 · 1 comment
Open

Consider adding #[must_use] to #[table] rows in Rust modules #2261

kazimuth opened this issue Feb 13, 2025 · 1 comment

Comments

@kazimuth
Copy link
Contributor

kazimuth commented Feb 13, 2025

Upsides

This would catch anywhere the user updates a row struct but forgets to commit it. This is likely to be particularly helpful to new users who don't understand the data model, but it would help experienced users as well.

E.g.

fn update_username(ctx: &ReducerContext, id: UID, name: String) {
   let mut user = ctx.db.user().id().find(id);
   user.name = name;
   // whoops! this does nothing!!
}

Downsides

You have to explicitly discard rows you don't need, e.g.

fn update_username(ctx: &ReducerContext, id: UID, name: String) {
   let mut user = ctx.db.user().id().find(id);
   user.name = name;
   // now you need this `let _ =` to avoid a warning, because the `update` method returns the updated row.
   let _ = ctx.db.user().id().update(user);
}

This makes using Row structs as plain-old-structs slightly less convenient. I still think it's worth it.

@gefjon
Copy link
Contributor

gefjon commented Feb 14, 2025

unused_must_use is warn by default, right? Not a hard error?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants