diff options
Diffstat (limited to 'src/tuice/key.rs')
-rw-r--r-- | src/tuice/key.rs | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/src/tuice/key.rs b/src/tuice/key.rs new file mode 100644 index 00000000..11e00ee5 --- /dev/null +++ b/src/tuice/key.rs @@ -0,0 +1,26 @@ +//! 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>); + +/// 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, + } + } +} |