Relaxation of reference rules for single-threaded applications

set(val) is copying val, right?

So is assignment.

2 Likes

Vec<X>, where X is a struct with many fields when I want to modify one of those fields, being turned into a &[Cell<X>] is not helpful in this case. I do not want to copy X. I want to modify one of many fields of X, or one of many sub-fields of X's fields, etc.

This could be done with cell projecting (i.e. getting a &Cell to a field given a &Cell to the whole struct). Unfortunately this is not yet supported in the stdlib/at the language level, but there are crates that implement this using macros, like cell-project.

Another alternative could be using the GhostCell from the ghost-cell crate instead of Cell, as that allows you to actually get a reference to the contents of the GhostCells which you can use to mutate only the field you care about.

1 Like

I've taken a look at cell-project, ghost-shell (and subsequently some others), and here's what I have found:

  • Relative to other popular and mature packages, very few people seem to be using these packages. In truth it may feel bad to use GitHub stars and crates-io downloads as an indicator of health/success of a package, but I simply do not have the time or expertise to evaluate all of the packages I use fully.
  • These packages have varying levels of maturity, for example some of ghost-cell's most recent commit comments were about unsoundness issues, which is alarming to say the least.

At this stage I don't think I am looking for an immediate download-from-crates-io solution. I'd like for this post to be one of maybe a small but growing number of signals from the community that an out-of-the-box language-solution to this problem would be awesome.

I do think the paper that ghost-cell cites as its source of inspiration sounds strikingly similar to my suggestion of being able to label references. The devil is in those details somewhere and I don't actually understand them, but I'd bet the authors of the paper do. Link to that here: GhostCell: Separating Permissions from Data in Rust

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.