turbo_tasks/
key_value_pair.rs

1use std::fmt::Debug;
2
3pub trait KeyValuePair {
4    type Type: Debug + Copy + Clone + PartialEq + Eq + std::hash::Hash;
5    type Key: Debug + Clone + PartialEq + Eq + std::hash::Hash;
6    type Value: Debug + Clone + Default + PartialEq + Eq;
7    type ValueRef<'l>: Debug + Copy + Clone + PartialEq + Eq + 'l
8    where
9        Self: 'l;
10    type ValueRefMut<'l>: Debug + PartialEq + Eq + 'l
11    where
12        Self: 'l;
13    fn ty(&self) -> Self::Type;
14    fn key(&self) -> Self::Key;
15    fn value(&self) -> Self::Value;
16    fn value_ref(&self) -> Self::ValueRef<'_>;
17    fn value_mut(&mut self) -> Self::ValueRefMut<'_>;
18    fn from_key_and_value(key: Self::Key, value: Self::Value) -> Self;
19    fn from_key_and_value_ref(key: Self::Key, value_ref: Self::ValueRef<'_>) -> Self;
20    fn into_key_and_value(self) -> (Self::Key, Self::Value);
21}
22
23/// Derives the [`KeyValuePair`][trait@KeyValuePair] trait for a enum. Each variant need to
24/// have a `value` field which becomes part of the value enum and all remaining fields become
25/// part of the key.
26///
27/// Assuming the enum is called `Abc` it exposes `AbcKey` and `AbcValue` types for it too. The
28/// key enum will have [`Debug`], [`Clone`], [`PartialEq`], [`Eq`], and [`Hash`] derived. The
29/// value enum will have [`Debug`] and [`Clone`] derived. It's expected that all fields
30/// implement these traits.
31pub use turbo_tasks_macros::KeyValuePair;