Skip to content

Commit e102666

Browse files
committed
Implement {Send, Sync} for {Iter, IterMut}
1 parent e2d0c7f commit e102666

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

src/lib.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -728,6 +728,14 @@ pub struct IterMut<'a, K: 'a, V: 'a> {
728728
marker: marker::PhantomData<(&'a K, &'a mut V)>,
729729
}
730730

731+
unsafe impl<'a, K, V> Send for Iter<'a, K, V> where K: Send, V: Send {}
732+
733+
unsafe impl<'a, K, V> Send for IterMut<'a, K, V> where K: Send, V: Send {}
734+
735+
unsafe impl<'a, K, V> Sync for Iter<'a, K, V> where K: Sync, V: Sync {}
736+
737+
unsafe impl<'a, K, V> Sync for IterMut<'a, K, V> where K: Sync, V: Sync {}
738+
731739
impl<'a, K, V> Clone for Iter<'a, K, V> {
732740
fn clone(&self) -> Self { Iter { ..*self } }
733741
}

tests/test.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,3 +220,14 @@ fn test_borrow() {
220220
assert_eq!(map.remove(&Foo(Bar(1))), None);
221221
assert_eq!(map.remove(&Foo(Bar(2))), None);
222222
}
223+
224+
#[test]
225+
fn test_send_sync() {
226+
fn is_send_sync<T: Send + Sync>() {}
227+
228+
is_send_sync::<LinkedHashMap<u32, i32>>();
229+
is_send_sync::<linked_hash_map::Iter<u32, i32>>();
230+
is_send_sync::<linked_hash_map::IterMut<u32, i32>>();
231+
is_send_sync::<linked_hash_map::Keys<u32, i32>>();
232+
is_send_sync::<linked_hash_map::Values<u32, i32>>();
233+
}

0 commit comments

Comments
 (0)