summaryrefslogtreecommitdiffstats
path: root/src/tuine/key.rs
blob: 05e70152fbf188e27faa64352734c62bc9396a8d (plain)
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,
        }
    }
}