Skip to content

Commit

Permalink
clean up documentation examples
Browse files Browse the repository at this point in the history
  • Loading branch information
ibraheemdev committed Nov 30, 2024
1 parent 2a5fc43 commit bae6b1b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 35 deletions.
37 changes: 16 additions & 21 deletions src/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -398,10 +398,9 @@ where
/// use papaya::HashMap;
///
/// let map = HashMap::new();
/// let m = map.pin();
/// m.insert(1, "a");
/// assert_eq!(m.contains_key(&1), true);
/// assert_eq!(m.contains_key(&2), false);
/// map.pin().insert(1, "a");
/// assert_eq!(map.pin().contains_key(&1), true);
/// assert_eq!(map.pin().contains_key(&2), false);
/// ```
#[inline]
pub fn contains_key<Q>(&self, key: &Q, guard: &impl Guard) -> bool
Expand All @@ -427,10 +426,9 @@ where
/// use papaya::HashMap;
///
/// let map = HashMap::new();
/// let m = map.pin();
/// m.insert(1, "a");
/// assert_eq!(m.get(&1), Some(&"a"));
/// assert_eq!(m.get(&2), None);
/// map.pin().insert(1, "a");
/// assert_eq!(map.pin().get(&1), Some(&"a"));
/// assert_eq!(map.pin().get(&2), None);
/// ```
#[inline]
pub fn get<'g, Q>(&self, key: &Q, guard: &'g impl Guard) -> Option<&'g V>
Expand Down Expand Up @@ -462,10 +460,9 @@ where
/// use papaya::HashMap;
///
/// let map = HashMap::new();
/// let m = map.pin();
/// m.insert(1, "a");
/// assert_eq!(m.get_key_value(&1), Some((&1, &"a")));
/// assert_eq!(m.get_key_value(&2), None);
/// map.pin().insert(1, "a");
/// assert_eq!(map.pin().get_key_value(&1), Some((&1, &"a")));
/// assert_eq!(map.pin().get_key_value(&2), None);
/// ```
#[inline]
pub fn get_key_value<'g, Q>(&self, key: &Q, guard: &'g impl Guard) -> Option<(&'g K, &'g V)>
Expand Down Expand Up @@ -499,12 +496,9 @@ where
/// assert_eq!(map.pin().insert(37, "a"), None);
/// assert_eq!(map.pin().is_empty(), false);
///
/// // note: you can also re-use a map pin like so:
/// let m = map.pin();
///
/// m.insert(37, "b");
/// assert_eq!(m.insert(37, "c"), Some(&"b"));
/// assert_eq!(m.get(&37), Some(&"c"));
/// map.pin().insert(37, "b");
/// assert_eq!(map.pin().insert(37, "c"), Some(&"b"));
/// assert_eq!(map.pin().get(&37), Some(&"c"));
/// ```
#[inline]
pub fn insert<'g>(&self, key: K, value: V, guard: &'g impl Guard) -> Option<&'g V> {
Expand All @@ -530,10 +524,11 @@ where
/// use papaya::HashMap;
///
/// let map = HashMap::new();
/// let m = map.pin();
/// assert_eq!(m.try_insert(37, "a").unwrap(), &"a");
/// let map = map.pin();
///
/// assert_eq!(map.try_insert(37, "a").unwrap(), &"a");
///
/// let err = m.try_insert(37, "b").unwrap_err();
/// let err = map.try_insert(37, "b").unwrap_err();
/// assert_eq!(err.current, &"a");
/// assert_eq!(err.not_inserted, "b");
/// ```
Expand Down
23 changes: 9 additions & 14 deletions src/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -359,10 +359,9 @@ where
/// use papaya::HashSet;
///
/// let set = HashSet::new();
/// let m = set.pin();
/// m.insert(1);
/// assert_eq!(m.contains(&1), true);
/// assert_eq!(m.contains(&2), false);
/// set.pin().insert(1);
/// assert_eq!(set.pin().contains(&1), true);
/// assert_eq!(set.pin().contains(&2), false);
/// ```
#[inline]
pub fn contains<Q>(&self, key: &Q, guard: &impl Guard) -> bool
Expand All @@ -388,10 +387,9 @@ where
/// use papaya::HashSet;
///
/// let set = HashSet::new();
/// let m = set.pin();
/// m.insert(1);
/// assert_eq!(m.get(&1), Some(&1));
/// assert_eq!(m.get(&2), None);
/// set.pin().insert(1);
/// assert_eq!(set.pin().get(&1), Some(&1));
/// assert_eq!(set.pin().get(&2), None);
/// ```
#[inline]
pub fn get<'g, Q>(&self, key: &Q, guard: &'g impl Guard) -> Option<&'g K>
Expand Down Expand Up @@ -428,12 +426,9 @@ where
/// assert_eq!(set.pin().insert(37), true);
/// assert_eq!(set.pin().is_empty(), false);
///
/// // note: you can also re-use a set pin like so:
/// let m = set.pin();
///
/// m.insert(37);
/// assert_eq!(m.insert(37), false);
/// assert_eq!(m.get(&37), Some(&37));
/// set.pin().insert(37);
/// assert_eq!(set.pin().insert(37), false);
/// assert_eq!(set.pin().get(&37), Some(&37));
/// ```
#[inline]
pub fn insert(&self, key: K, guard: &impl Guard) -> bool {
Expand Down

0 comments on commit bae6b1b

Please sign in to comment.