I have several types of Copy , and I am very grateful for the convenience of using Copy .
I would like one of these types to contain a mutable field using the Interior Mutability function, as in cell::Cell . There are probably other solutions to the problem I'm trying to solve, but the internal mutability is cheap. I like it cheaply.
However, it turns out that cell::Cell not Copy , and from the comments Copy unlikely to become, as the attendants fear that this will be error prone.
OP comment is my current beacon of hope:
This is not an absolute end of the world, if it is not for my own data structures (since I can just make my own version of Cell )
Although I do not see how they intend to achieve this success.
The main question I have is that UnsafeCell :
- is required to implement internal interchangeability,
- not
Copy .
Which seems to close the door to any hope of implementing CopyCell if I miss the trick (the path to unsafe impl Copy ?).
MCVE :
#[derive(Clone, Copy)] struct HelloWorld(Cell<u32>);
| 3 | #[derive(Clone, Copy)] | ^^^^ 4 | struct HelloWorld(Cell<u32>); | ---------- this field does not implement `Copy`
What should I replace Cell with HelloWorld as Copy ?
Note: at the moment, the only way to see the desired result is to use &Cell<T> ; with all the consequences of life.
source share