framework_timer/name.rs
1/// 可被定时任务运行时按名称匹配的类型。
2///
3/// 已为字符串类型与 `generate_name` 生成的枚举提供实现,因此 [`crate::wake`]
4/// 既能接受 `"task_name"` 这样的字面量,也能接受生成的名称枚举。
5pub trait TimerNameLike {
6 /// 返回与 [`crate::TimerRegistration::name`] 一致的原始任务函数名。
7 fn timer_name(&self) -> &str;
8}
9
10impl TimerNameLike for &str {
11 fn timer_name(&self) -> &str {
12 self
13 }
14}
15
16impl TimerNameLike for String {
17 fn timer_name(&self) -> &str {
18 self
19 }
20}
21
22impl TimerNameLike for &String {
23 fn timer_name(&self) -> &str {
24 self
25 }
26}
27
28impl TimerNameLike for std::borrow::Cow<'_, str> {
29 fn timer_name(&self) -> &str {
30 self
31 }
32}