Skip to content

Commit c50e3f6

Browse files
committed
Metnion Cell constructor option
1 parent 3fe52dd commit c50e3f6

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

text/0000-as-cell.md

+16-1
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,22 @@ an example implementation and a more complex use case.
167167
[alternatives]: #alternatives
168168

169169
Instead of a dedicated trait, the functionality could be provided
170-
by standalone functions like this:
170+
as `Cell` constructors:
171+
172+
```rust
173+
174+
impl<T: Copy> Cell<T> {
175+
fn from_mut<'a>(t: &'a mut T) -> &'a Cell<T> {
176+
unsafe { mem::transmute(t) }
177+
}
178+
fn from_mut<'a>(t: &'a mut [T]) -> &'a [Cell<T>] {
179+
unsafe { mem::transmute(t) }
180+
}
181+
}
182+
183+
```
184+
185+
Or more simple, by standalone functions like this:
171186

172187
```rust
173188
fn ref_as_cell<T: Copy>(t: &mut T) -> &Cell<T> {

0 commit comments

Comments
 (0)