Files
rust/src
kennytm 91cc872987 Rollup merge of #49727 - stjepang:cell-update, r=SimonSapin
Add Cell::update

This commit adds a new method `Cell::update`, which applies a function to the value inside the cell.

Previously discussed in: https://github.com/rust-lang/rfcs/issues/2171

### Motivation

Updating `Cell`s is currently a bit verbose. Here are several real examples (taken from rustc and crossbeam):

```rust
self.print_fuel.set(self.print_fuel.get() + 1);

self.diverges.set(self.diverges.get() | Diverges::Always);

let guard_count = self.guard_count.get();
self.guard_count.set(guard_count.checked_add(1).unwrap());
if guard_count == 0 {
    // ...
}
```

With the addition of the new method `Cell::update`, this code can be simplified to:

```rust
self.print_fuel.update(|x| x + 1);

self.diverges.update(|x| x | Diverges::Always);

if self.guard_count.update(|x| x.checked_add(1).unwrap()) == 1 {
    // ...
}
```

### Unresolved questions

1. Should we return the old value instead of the new value (like in `fetch_add` and `fetch_update`)?
2. Should the return type simply be `()`?
3. Naming: `update` vs `modify` vs `mutate` etc.

cc @SimonSapin
2018-04-24 11:57:00 +08:00
..
2018-04-12 14:49:03 +09:00
2018-04-22 00:30:48 +02:00
2018-04-22 10:08:49 -07:00
2018-04-22 10:08:49 -07:00
2018-04-22 10:08:49 -07:00
2018-04-15 20:53:03 +02:00
2018-04-15 20:53:03 +02:00
2018-04-15 23:49:41 +02:00
2018-04-16 23:37:11 +02:00
2018-04-19 23:47:28 +02:00
2018-04-22 20:35:22 -05:00
2018-04-22 20:35:22 -05:00

This directory contains the source code of the rust project, including:

  • rustc and its tests
  • libstd
  • Various submodules for tools, like rustdoc, rls, etc.

For more information on how various parts of the compiler work, see the rustc guide.

Their is also useful content in the following READMEs, which are gradually being moved over to the guide: