ObservableHashMap

Struct ObservableHashMap 

Source
pub struct ObservableHashMap<K, V, Codec = Default> { /* private fields */ }
๐Ÿ‘ŽDeprecated: remoc-obs has been integrated into remoc as module remoc::robs. Please update your references.
Expand description

A hash map that emits an event for each change.

Use subscribe to obtain an event stream that can be used for building a mirror of this hash map.

Implementationsยง

Sourceยง

impl<K, V, Codec> ObservableHashMap<K, V, Codec>
where K: Eq + Hash + Clone + RemoteSend, V: Clone + RemoteSend, Codec: Codec,

Source

pub fn new() -> Self

๐Ÿ‘ŽDeprecated: remoc-obs has been integrated into remoc as module remoc::robs. Please update your references.

Creates an empty observable hash map.

Source

pub fn set_error_handler<E>(&mut self, on_err: E)
where E: Fn(SendError) + Send + Sync + 'static,

๐Ÿ‘ŽDeprecated: remoc-obs has been integrated into remoc as module remoc::robs. Please update your references.

Sets the error handler function that is called when sending an event fails.

Source

pub fn subscribe(&self, buffer: usize) -> HashMapSubscription<K, V, Codec>

๐Ÿ‘ŽDeprecated: remoc-obs has been integrated into remoc as module remoc::robs. Please update your references.

Subscribes to change events from this observable hash map.

The current contents of the hash map is included with the subscription.

buffer specifies the maximum size of the event buffer for this subscription in number of events. If it is exceeded the subscription is shed and the receiver gets a RecvError::Lagged.

Source

pub fn subscribe_incremental( &self, buffer: usize, ) -> HashMapSubscription<K, V, Codec>

๐Ÿ‘ŽDeprecated: remoc-obs has been integrated into remoc as module remoc::robs. Please update your references.

Subscribes to change events from this observable hash map with incremental sending of the current contents.

The current contents of the hash map are sent incrementally.

buffer specifies the maximum size of the event buffer for this subscription in number of events. If it is exceeded the subscription is shed and the receiver gets a RecvError::Lagged.

Source

pub fn subscriber_count(&self) -> usize

๐Ÿ‘ŽDeprecated: remoc-obs has been integrated into remoc as module remoc::robs. Please update your references.

Current number of subscribers.

Source

pub fn notifier(&self) -> ChangeNotifier

๐Ÿ‘ŽDeprecated: remoc-obs has been integrated into remoc as module remoc::robs. Please update your references.

Returns a change notifier that can be used locally to be notified of changes to this collection.

Source

pub fn insert(&mut self, k: K, v: V) -> Option<V>

๐Ÿ‘ŽDeprecated: remoc-obs has been integrated into remoc as module remoc::robs. Please update your references.

Inserts a value under a key.

A HashMapEvent::Set change event is sent.

Returns the value previously stored under the key, if any.

ยงPanics

Panics when done has been called before.

Source

pub fn remove<Q>(&mut self, k: &Q) -> Option<V>
where K: Borrow<Q>, Q: Hash + Eq,

๐Ÿ‘ŽDeprecated: remoc-obs has been integrated into remoc as module remoc::robs. Please update your references.

Removes the value under the specified key.

A HashMapEvent::Remove change event is sent.

The value is returned.

ยงPanics

Panics when done has been called before.

Source

pub fn clear(&mut self)

๐Ÿ‘ŽDeprecated: remoc-obs has been integrated into remoc as module remoc::robs. Please update your references.

Removes all items.

A HashMapEvent::Clear change event is sent.

ยงPanics

Panics when done has been called before.

Source

pub fn retain<F>(&mut self, f: F)
where F: FnMut(&K, &mut V) -> bool,

๐Ÿ‘ŽDeprecated: remoc-obs has been integrated into remoc as module remoc::robs. Please update your references.

Retains only the elements specified by the predicate.

A HashMapEvent::Remove change event is sent for every element that is removed.

ยงPanics

Panics when done has been called before.

Source

pub fn entry(&mut self, key: K) -> Entry<'_, K, V, Codec>

๐Ÿ‘ŽDeprecated: remoc-obs has been integrated into remoc as module remoc::robs. Please update your references.

Gets the given keyโ€™s corresponding entry in the map for in-place manipulation.

ยงPanics

Panics when done has been called before.

Source

pub fn get_mut<Q>(&mut self, k: &Q) -> Option<RefMut<'_, K, V, Codec>>
where K: Borrow<Q>, Q: Hash + Eq,

๐Ÿ‘ŽDeprecated: remoc-obs has been integrated into remoc as module remoc::robs. Please update your references.

Gets a mutable reference to the value under the specified key.

A HashMapEvent::Set change event is sent if the reference is accessed mutably.

ยงPanics

Panics when done has been called before.

Source

pub fn iter_mut(&mut self) -> IterMut<'_, K, V, Codec> โ“˜

๐Ÿ‘ŽDeprecated: remoc-obs has been integrated into remoc as module remoc::robs. Please update your references.

Mutably iterates over the key-value pairs.

A HashMapEvent::Set change event is sent for each value that is accessed mutably.

ยงPanics

Panics when done has been called before.

Source

pub fn shrink_to_fit(&mut self)

๐Ÿ‘ŽDeprecated: remoc-obs has been integrated into remoc as module remoc::robs. Please update your references.

Shrinks the capacity of the hash map as much as possible.

A HashMapEvent::ShrinkToFit change event is sent.

ยงPanics

Panics when done has been called before.

Source

pub fn done(&mut self)

๐Ÿ‘ŽDeprecated: remoc-obs has been integrated into remoc as module remoc::robs. Please update your references.

Prevents further changes of this hash map and notifies are subscribers that no further events will occur.

Methods that modify the hash map will panic after this has been called. It is still possible to subscribe to this observable hash map.

Source

pub fn is_done(&self) -> bool

๐Ÿ‘ŽDeprecated: remoc-obs has been integrated into remoc as module remoc::robs. Please update your references.

Returns true if done has been called and further changes are prohibited.

Methods that modify the hash map will panic in this case.

Source

pub fn into_inner(self) -> HashMap<K, V>

๐Ÿ‘ŽDeprecated: remoc-obs has been integrated into remoc as module remoc::robs. Please update your references.

Extracts the underlying hash map.

If done has not been called before this method, subscribers will receive an error.

Methods from Deref<Target = HashMap<K, V>>ยง

1.0.0 ยท Source

pub fn capacity(&self) -> usize

Returns the number of elements the map can hold without reallocating.

This number is a lower bound; the HashMap<K, V> might be able to hold more, but is guaranteed to be able to hold at least this many.

ยงExamples
use std::collections::HashMap;
let map: HashMap<i32, i32> = HashMap::with_capacity(100);
assert!(map.capacity() >= 100);
1.0.0 ยท Source

pub fn keys(&self) -> Keys<'_, K, V>

An iterator visiting all keys in arbitrary order. The iterator element type is &'a K.

ยงExamples
use std::collections::HashMap;

let map = HashMap::from([
    ("a", 1),
    ("b", 2),
    ("c", 3),
]);

for key in map.keys() {
    println!("{key}");
}
ยงPerformance

In the current implementation, iterating over keys takes O(capacity) time instead of O(len) because it internally visits empty buckets too.

1.0.0 ยท Source

pub fn values(&self) -> Values<'_, K, V>

An iterator visiting all values in arbitrary order. The iterator element type is &'a V.

ยงExamples
use std::collections::HashMap;

let map = HashMap::from([
    ("a", 1),
    ("b", 2),
    ("c", 3),
]);

for val in map.values() {
    println!("{val}");
}
ยงPerformance

In the current implementation, iterating over values takes O(capacity) time instead of O(len) because it internally visits empty buckets too.

1.0.0 ยท Source

pub fn iter(&self) -> Iter<'_, K, V>

An iterator visiting all key-value pairs in arbitrary order. The iterator element type is (&'a K, &'a V).

ยงExamples
use std::collections::HashMap;

let map = HashMap::from([
    ("a", 1),
    ("b", 2),
    ("c", 3),
]);

for (key, val) in map.iter() {
    println!("key: {key} val: {val}");
}
ยงPerformance

In the current implementation, iterating over map takes O(capacity) time instead of O(len) because it internally visits empty buckets too.

1.0.0 ยท Source

pub fn len(&self) -> usize

Returns the number of elements in the map.

ยงExamples
use std::collections::HashMap;

let mut a = HashMap::new();
assert_eq!(a.len(), 0);
a.insert(1, "a");
assert_eq!(a.len(), 1);
1.0.0 ยท Source

pub fn is_empty(&self) -> bool

Returns true if the map contains no elements.

ยงExamples
use std::collections::HashMap;

let mut a = HashMap::new();
assert!(a.is_empty());
a.insert(1, "a");
assert!(!a.is_empty());
1.9.0 ยท Source

pub fn hasher(&self) -> &S

Returns a reference to the mapโ€™s BuildHasher.

ยงExamples
use std::collections::HashMap;
use std::hash::RandomState;

let hasher = RandomState::new();
let map: HashMap<i32, i32> = HashMap::with_hasher(hasher);
let hasher: &RandomState = map.hasher();
1.0.0 ยท Source

pub fn get<Q>(&self, k: &Q) -> Option<&V>
where K: Borrow<Q>, Q: Hash + Eq + ?Sized,

Returns a reference to the value corresponding to the key.

The key may be any borrowed form of the mapโ€™s key type, but Hash and Eq on the borrowed form must match those for the key type.

ยงExamples
use std::collections::HashMap;

let mut map = HashMap::new();
map.insert(1, "a");
assert_eq!(map.get(&1), Some(&"a"));
assert_eq!(map.get(&2), None);
1.40.0 ยท Source

pub fn get_key_value<Q>(&self, k: &Q) -> Option<(&K, &V)>
where K: Borrow<Q>, Q: Hash + Eq + ?Sized,

Returns the key-value pair corresponding to the supplied key. This is potentially useful:

  • for key types where non-identical keys can be considered equal;
  • for getting the &K stored key value from a borrowed &Q lookup key; or
  • for getting a reference to a key with the same lifetime as the collection.

The supplied key may be any borrowed form of the mapโ€™s key type, but Hash and Eq on the borrowed form must match those for the key type.

ยงExamples
use std::collections::HashMap;
use std::hash::{Hash, Hasher};

#[derive(Clone, Copy, Debug)]
struct S {
    id: u32,
    name: &'static str, // ignored by equality and hashing operations
}

impl PartialEq for S {
    fn eq(&self, other: &S) -> bool {
        self.id == other.id
    }
}

impl Eq for S {}

impl Hash for S {
    fn hash<H: Hasher>(&self, state: &mut H) {
        self.id.hash(state);
    }
}

let j_a = S { id: 1, name: "Jessica" };
let j_b = S { id: 1, name: "Jess" };
let p = S { id: 2, name: "Paul" };
assert_eq!(j_a, j_b);

let mut map = HashMap::new();
map.insert(j_a, "Paris");
assert_eq!(map.get_key_value(&j_a), Some((&j_a, &"Paris")));
assert_eq!(map.get_key_value(&j_b), Some((&j_a, &"Paris"))); // the notable case
assert_eq!(map.get_key_value(&p), None);
1.0.0 ยท Source

pub fn contains_key<Q>(&self, k: &Q) -> bool
where K: Borrow<Q>, Q: Hash + Eq + ?Sized,

Returns true if the map contains a value for the specified key.

The key may be any borrowed form of the mapโ€™s key type, but Hash and Eq on the borrowed form must match those for the key type.

ยงExamples
use std::collections::HashMap;

let mut map = HashMap::new();
map.insert(1, "a");
assert_eq!(map.contains_key(&1), true);
assert_eq!(map.contains_key(&2), false);

Trait Implementationsยง

Sourceยง

impl<K, V, Codec> Debug for ObservableHashMap<K, V, Codec>
where K: Debug, V: Debug,

Sourceยง

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Sourceยง

impl<K, V, Codec> Default for ObservableHashMap<K, V, Codec>
where K: Clone + RemoteSend, V: Clone + RemoteSend, Codec: Codec,

Sourceยง

fn default() -> Self

Returns the โ€œdefault valueโ€ for a type. Read more
Sourceยง

impl<K, V, Codec> Deref for ObservableHashMap<K, V, Codec>

Sourceยง

type Target = HashMap<K, V>

The resulting type after dereferencing.
Sourceยง

fn deref(&self) -> &Self::Target

Dereferences the value.
Sourceยง

impl<K, V, Codec> Extend<(K, V)> for ObservableHashMap<K, V, Codec>
where K: Eq + Hash + Clone + RemoteSend, V: Clone + RemoteSend, Codec: Codec,

Sourceยง

fn extend<I: IntoIterator<Item = (K, V)>>(&mut self, iter: I)

Extends a collection with the contents of an iterator. Read more
Sourceยง

fn extend_one(&mut self, item: A)

๐Ÿ”ฌThis is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
Sourceยง

fn extend_reserve(&mut self, additional: usize)

๐Ÿ”ฌThis is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
Sourceยง

impl<K, V, Codec> From<HashMap<K, V>> for ObservableHashMap<K, V, Codec>
where K: Clone + RemoteSend, V: Clone + RemoteSend, Codec: Codec,

Sourceยง

fn from(hm: HashMap<K, V>) -> Self

Converts to this type from the input type.
Sourceยง

impl<K, V, Codec> From<ObservableHashMap<K, V, Codec>> for HashMap<K, V>

Sourceยง

fn from(ohm: ObservableHashMap<K, V, Codec>) -> Self

Converts to this type from the input type.

Auto Trait Implementationsยง

ยง

impl<K, V, Codec> Freeze for ObservableHashMap<K, V, Codec>

ยง

impl<K, V, Codec = Default> !RefUnwindSafe for ObservableHashMap<K, V, Codec>

ยง

impl<K, V, Codec> Send for ObservableHashMap<K, V, Codec>
where K: Send, V: Send, Codec: Send,

ยง

impl<K, V, Codec> Sync for ObservableHashMap<K, V, Codec>
where K: Sync + Send, V: Sync + Send, Codec: Send,

ยง

impl<K, V, Codec> Unpin for ObservableHashMap<K, V, Codec>
where K: Unpin, V: Unpin,

ยง

impl<K, V, Codec = Default> !UnwindSafe for ObservableHashMap<K, V, Codec>

Blanket Implementationsยง

Sourceยง

impl<T> Any for T
where T: 'static + ?Sized,

Sourceยง

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Sourceยง

impl<T> Borrow<T> for T
where T: ?Sized,

Sourceยง

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Sourceยง

impl<T> BorrowMut<T> for T
where T: ?Sized,

Sourceยง

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Sourceยง

impl<T> From<T> for T

Sourceยง

fn from(t: T) -> T

Returns the argument unchanged.

Sourceยง

impl<T> Instrument for T

Sourceยง

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Sourceยง

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Sourceยง

impl<T, U> Into<U> for T
where U: From<T>,

Sourceยง

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Sourceยง

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Sourceยง

type Target = T

๐Ÿ”ฌThis is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Sourceยง

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Sourceยง

type Error = Infallible

The type returned in the event of a conversion error.
Sourceยง

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Sourceยง

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Sourceยง

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Sourceยง

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Sourceยง

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Sourceยง

fn vzip(self) -> V

Sourceยง

impl<T> WithSubscriber for T

Sourceยง

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Sourceยง

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more