compose_rt/
loc.rs

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
33
34
35
use std::fmt::{Debug, Formatter, Result};
use std::hash::Hash;
use std::panic::Location;

#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
pub struct Loc {
    location: &'static Location<'static>,
}

impl Loc {
    #[track_caller]
    #[inline(always)]
    pub const fn new() -> Self {
        Self {
            location: Location::caller(),
        }
    }

    #[inline(always)]
    pub fn id(&self) -> usize {
        self.location as *const _ as usize
    }
}

impl Debug for Loc {
    fn fmt(&self, f: &mut Formatter<'_>) -> Result {
        write!(f, "{}", self.location)
    }
}

impl Hash for Loc {
    fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
        self.id().hash(state);
    }
}