1use std::fmt::{Debug, Formatter, Result};
2use std::hash::Hash;
3use std::panic::Location;
4
5#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
6pub struct Loc {
7 location: &'static Location<'static>,
8}
9
10impl Loc {
11 #[track_caller]
12 #[inline(always)]
13 pub const fn new() -> Self {
14 Self {
15 location: Location::caller(),
16 }
17 }
18
19 #[inline(always)]
20 pub fn id(&self) -> usize {
21 self.location as *const _ as usize
22 }
23}
24
25impl Debug for Loc {
26 fn fmt(&self, f: &mut Formatter<'_>) -> Result {
27 write!(f, "{}", self.location)
28 }
29}
30
31impl Hash for Loc {
32 fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
33 self.id().hash(state);
34 }
35}