cranpose_core/
task_site.rs1#[derive(Clone, Copy, Debug, PartialEq, Eq)]
8pub struct TaskSite {
9 pub file: &'static str,
11 pub line: u32,
13}
14
15impl TaskSite {
16 pub const fn new(file: &'static str, line: u32) -> Self {
18 Self { file, line }
19 }
20}
21
22impl Default for TaskSite {
23 fn default() -> Self {
24 Self::new("unknown", 0)
25 }
26}
27
28impl std::fmt::Display for TaskSite {
29 fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
30 write!(formatter, "{}:{}", self.file, self.line)
31 }
32}
33
34impl From<&'static std::panic::Location<'static>> for TaskSite {
35 fn from(location: &'static std::panic::Location<'static>) -> Self {
36 Self::new(location.file(), location.line())
37 }
38}
39
40#[derive(Clone, Copy)]
43pub(crate) enum TaskLabel {
44 Unnamed,
45 Site(TaskSite),
46}
47
48impl std::fmt::Display for TaskLabel {
49 fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
50 match self {
51 Self::Unnamed => formatter.write_str("unnamed"),
52 Self::Site(site) => site.fmt(formatter),
53 }
54 }
55}