Skip to main content

zrx_store/store/
item.rs

1// Copyright (c) 2025-2026 Zensical and contributors
2
3// SPDX-License-Identifier: MIT
4// All contributions are certified under the DCO
5
6// Permission is hereby granted, free of charge, to any person obtaining a copy
7// of this software and associated documentation files (the "Software"), to
8// deal in the Software without restriction, including without limitation the
9// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10// sell copies of the Software, and to permit persons to whom the Software is
11// furnished to do so, subject to the following conditions:
12
13// The above copyright notice and this permission notice shall be included in
14// all copies or substantial portions of the Software.
15
16// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18// FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
19// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
22// IN THE SOFTWARE.
23
24// ----------------------------------------------------------------------------
25
26//! Store key and value.
27
28use std::fmt::Debug;
29use std::hash::Hash;
30
31// ----------------------------------------------------------------------------
32// Traits
33// ----------------------------------------------------------------------------
34
35/// Store key.
36///
37/// This trait defines the basic requirements for a key used in a [`Store`][].
38/// We can't use specific traits, e.g., [`Eq`][] + [`Hash`][] for hash maps or
39/// [`Ord`][] for ordered keys, since we would lose the ability to allow for
40/// using [`Borrow`][] to generalize the key type.
41///
42/// Keys must implement [`Clone`], [`Debug`], [`Eq`], [`Hash`] and [`Ord`], all
43/// of which we consider reasonable requirements for a generic API.
44///
45/// __Warning__: The `'static` lifetime which is required by this trait is a
46/// deliberate design choice to simplify trait bounds across the code base. If
47/// we would not require the lifetime, we would need to add a lifetime parameter
48/// to almost all types using this trait, which makes it cumbersome to use.
49///
50/// [`Borrow`]: std::borrow::Borrow
51/// [`Store`]: crate::store::Store
52pub trait Key: Clone + Debug + Eq + Hash + Ord + 'static {}
53
54/// Store value.
55///
56/// __Warning__: The `'static` lifetime which is required by this trait is a
57/// deliberate design choice to simplify trait bounds across the code base. If
58/// we would not require the lifetime, we would need to add a lifetime parameter
59/// to almost all types using this trait, which makes it cumbersome to use.
60///
61/// [`Store`]: crate::store::Store
62pub trait Value: Debug + 'static {}
63
64// ----------------------------------------------------------------------------
65// Blanket implementations
66// ----------------------------------------------------------------------------
67
68impl<T> Key for T where T: Clone + Debug + Eq + Hash + Ord + 'static {}
69
70impl<T> Value for T where T: Debug + 'static {}