A `swap` method for `Cell`?

#1

I wonder if we could safely provide the following method:

impl<T> Cell<T> {
    fn swap(&self, other: &mut T);
}

Note the absence of a Copy bound, unlike get and set. The important things for Cell are that you can’t borrow the content, only read and write it, and that doing so doesn’t call back into user code via e.g. clone(). These would be preserved, so I think this should be safe.

(For this to be useful, the new() method should also lose the Copy bound.)

Use case: None in particular. I just thought it was interesting.

Going further, we could also have:

fn swap_cells<T>(one: &Cell<T>, other: &Cell<T>); // dunno name
1 Like

closed #2

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

0 Likes