1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
//! Code here is based on crochet's implementation - see
//! [here](https://github.com/raphlinus/crochet/blob/master/src/key.rs) for more details!
use std::hash::Hash;
use std::panic::Location;
/// A newtype around [`Location`].
#[derive(Clone, Copy, Hash, Debug, PartialEq, Eq, PartialOrd, Ord)]
pub struct Caller(&'static Location<'static>);
impl From<&'static Location<'static>> for Caller {
fn from(location: &'static Location<'static>) -> Self {
Caller(location)
}
}
/// A unique key built around using the [`Location`] given by
/// `#[track_caller]` and a sequence index.
#[derive(Clone, Copy, Hash, Debug, PartialEq, Eq, PartialOrd, Ord)]
pub struct Key {
pub(crate) caller: Caller,
pub(crate) index: usize,
}
impl Key {
pub fn new(caller: impl Into<Caller>, index: usize) -> Self {
Self {
caller: caller.into(),
index,
}
}
}
|