Skip to content

Commit aba44ab

Browse files
committed
Improved examples
1 parent c95e5c0 commit aba44ab

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

active/0000-deref-coercions.md

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ language, coercions included things like auto-borrowing (taking `T` to `&T`),
3636
auto-slicing (taking `Vec<T>` to `&[T]`) and "cross-borrowing" (taking `Box<T>`
3737
to `&T`). As built-in types migrated to the library, these coercions have
3838
disappeared: none of them apply today. That means that you have to write code
39-
like `&**v` to convert `Rc<Box<T>>` to `&T` and `v.as_slice()` to convert
40-
`Vec<T>` to `&T`.
39+
like `&**v` to convert `&Box<T>` or `Rc<RefCell<T>>` to `&T` and `v.as_slice()`
40+
to convert `Vec<T>` to `&T`.
4141

4242
The ergonomic regression was coupled with a promise that we'd improve things in
4343
a more general way later on.
@@ -176,15 +176,24 @@ Under this coercion design, we'd see the following ergonomic improvements for
176176

177177
```rust
178178
fn use_ref(t: &T) { ... }
179+
fn use_mut(t: &mut T) { ... }
179180

180181
fn use_rc(t: Rc<T>) {
181182
use_ref(&*t); // what you have to write today
182183
use_ref(&t); // what you'd be able to write
183184
}
184185

185-
fn use_nested(t: Rc<Box<T>>) {
186+
fn use_mut(t: &mut Box<T>) {
187+
use_mut(&mut *t); // what you have to write today
188+
use_mut(t); // what you'd be able to write
189+
190+
use_ref(*t); // what you have to write today
191+
use_ref(t); // what you'd be able to write
192+
}
193+
194+
fn use_nested(t: &Box<T>) {
186195
use_ref(&**t); // what you have to write today
187-
use_ref(&t); // what you'd be able to write (note: recursive deref)
196+
use_ref(t); // what you'd be able to write (note: recursive deref)
188197
}
189198
```
190199

0 commit comments

Comments
 (0)