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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/// Where an effect was written, carried onto the task it spawns.
///
/// A leak report that can only say "one task is still queued" names nothing.
/// Every run prints the same number. No run says which effect it was. The
/// site turns that count into a place to look. It is a pair of plain fields.
/// Carrying it costs nothing until a task is spawned.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct TaskSite {
/// The path of the source file, as `file!()` gives it.
pub file: &'static str,
/// The line number in `file`, counted from 1.
pub line: u32,
}
impl TaskSite {
/// The site a macro captured with `file!()` and `line!()`.
pub const fn new(file: &'static str, line: u32) -> Self {
Self { file, line }
}
}
impl Default for TaskSite {
fn default() -> Self {
Self::new("unknown", 0)
}
}
impl std::fmt::Display for TaskSite {
fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(formatter, "{}:{}", self.file, self.line)
}
}
impl From<&'static std::panic::Location<'static>> for TaskSite {
fn from(location: &'static std::panic::Location<'static>) -> Self {
Self::new(location.file(), location.line())
}
}
// What a spawned UI task is called in leak reports. A site is formatted only
// when a report asks. Spawning a task allocates no name.
#[derive(Clone, Copy)]
pub(crate) enum TaskLabel {
Unnamed,
Site(TaskSite),
}
impl std::fmt::Display for TaskLabel {
fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Unnamed => formatter.write_str("unnamed"),
Self::Site(site) => site.fmt(formatter),
}
}
}