diff --git a/src/id.rs b/src/id.rs index b679f3b..f6eee1c 100644 --- a/src/id.rs +++ b/src/id.rs @@ -80,11 +80,30 @@ impl Clone for Id where T: Message { } } -unsafe impl Sync for Id where T: Sync { } +/// The `Send` implementation requires `T: Sync` because `Id` give +/// access to `&T`. +/// +/// Additiontally, it requires `T: Send` because if `T: !Send`, you could +/// clone a `Id`, send it to another thread, and drop the clone +/// last, making `dealloc` get called on the other thread, and violate +/// `T: !Send`. +unsafe impl Send for Id {} + +/// The `Sync` implementation requires `T: Sync` because `&Id` give +/// access to `&T`. +/// +/// Additiontally, it requires `T: Send`, because if `T: !Send`, you could +/// clone a `&Id` from another thread, and drop the clone last, +/// making `dealloc` get called on the other thread, and violate `T: !Send`. +unsafe impl Sync for Id {} -unsafe impl Send for Id where T: Send { } +/// `Id` are `Send` if `T` is `Send` because they give the same +/// access as having a T directly. +unsafe impl Send for Id {} -unsafe impl Send for Id where T: Sync { } +/// `Id` are `Sync` if `T` is `Sync` because they give the same +/// access as having a `T` directly. +unsafe impl Sync for Id {} impl Deref for Id { type Target = T; @@ -161,9 +180,11 @@ impl WeakId where T: Message { } } -unsafe impl Sync for WeakId where T: Sync { } +/// This implementation follows the same reasoning as `Id`. +unsafe impl Sync for WeakId {} -unsafe impl Send for WeakId where T: Sync { } +/// This implementation follows the same reasoning as `Id`. +unsafe impl Send for WeakId {} #[cfg(test)] mod tests {