I sometimes find myself using a !Sync type (eg bumpalo::Bump) as part of the implementation of a type I want to be Sync. Right now I do it with unsafe impl Sync for the outer type, and only touching the inner type in &mut self methods. But is it sound to encapsulate the unsafety with a wrapper like the following? In particular, are the Send bounds correct?
pub struct UnCell<T> {
value: T
}
unsafe impl<T> Sync for UnCell<T> {}
impl<T> UnCell<T> {
pub fn new(value: T) -> Self {
Self { value }
}
pub fn into_inner(self) -> T {
self.value
}
pub fn get(&mut self) -> &T {
&self.value
}
}
impl<T: Send> UnCell<T> {
pub fn get_mut(&mut self) -> &mut T {
&mut self.value
}
}