SpacetimeDB
SpacetimeDB copied to clipboard
Consider adding `#[must_use]` to `#[table]` rows in Rust modules
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.
unused_must_use is warn by default, right? Not a hard error?
Assigning to dev ex team. They will prioritize as they see fit based on user reports (or lack thereof).