Skip to main content

acktor_ipc/double_map/
errors.rs

1use thiserror::Error;
2
3/// Error returned by [`DoubleMap::insert`][super::DoubleMap::insert] and
4/// [`DoubleMap::entry`][super::DoubleMap::entry] when one or both of the supplied
5/// keys clash with an existing entry in the map.
6///
7/// The rejected keys are returned in the variant payload so the caller can reuse
8/// them without cloning. `insert` additionally returns the rejected value, so its
9/// error type is `KeyConflictError<K1, K2, V>`; `entry` has no value to hand back
10/// and uses the default `V = ()`.
11#[derive(Debug, Error)]
12pub enum KeyConflictError<K1, K2, V = ()> {
13    /// `key1` is already present in the map (paired with a different `key2`),
14    /// while the supplied `key2` is not in the map.
15    #[error("key 1 is already present in the map paired with a different key 2")]
16    Key1Exists(K1, K2, V),
17
18    /// `key2` is already present in the map (paired with a different `key1`),
19    /// while the supplied `key1` is not in the map.
20    #[error("key 2 is already present in the map paired with a different key 1")]
21    Key2Exists(K1, K2, V),
22
23    /// Both `key1` and `key2` are already present in the map, but in different
24    /// entries.
25    #[error("both key 1 and key 2 are already present in the map but in different entries")]
26    BothKeysExist(K1, K2, V),
27}