icedwright_probe/
test_id.rs1use std::borrow::Cow;
4use std::fmt;
5
6pub trait TestId: Copy + fmt::Debug + 'static {
11 fn test_id(&self) -> Cow<'static, str>;
13
14 fn rust_path(&self) -> &'static str;
17
18 fn qualified_path(&self) -> &'static str {
22 self.rust_path()
23 }
24}
25
26#[derive(Debug, Clone, PartialEq, Eq, Hash)]
28pub struct TestIdRef<'a> {
29 pub id: Cow<'a, str>,
31 pub rust_path: Option<&'static str>,
33}
34
35impl TestIdRef<'_> {
36 #[must_use]
38 pub fn into_static(self) -> TestIdRef<'static> {
39 TestIdRef {
40 id: Cow::Owned(self.id.into_owned()),
41 rust_path: self.rust_path,
42 }
43 }
44}
45
46impl fmt::Display for TestIdRef<'_> {
47 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
48 f.write_str(&self.id)
49 }
50}
51
52pub trait IntoTestId<'a> {
55 fn into_test_id(self) -> TestIdRef<'a>;
57
58 fn qualified_rust_path(&self) -> Option<&'static str> {
60 None
61 }
62}
63
64impl<'a> IntoTestId<'a> for &'a str {
65 fn into_test_id(self) -> TestIdRef<'a> {
66 TestIdRef {
67 id: Cow::Borrowed(self),
68 rust_path: None,
69 }
70 }
71}
72
73impl<'a> IntoTestId<'a> for &'a String {
74 fn into_test_id(self) -> TestIdRef<'a> {
75 self.as_str().into_test_id()
76 }
77}
78
79impl IntoTestId<'_> for String {
80 fn into_test_id(self) -> TestIdRef<'static> {
81 TestIdRef {
82 id: Cow::Owned(self),
83 rust_path: None,
84 }
85 }
86}
87
88impl<'a> IntoTestId<'a> for Cow<'a, str> {
89 fn into_test_id(self) -> TestIdRef<'a> {
90 TestIdRef {
91 id: self,
92 rust_path: None,
93 }
94 }
95}
96
97impl<'a> IntoTestId<'a> for TestIdRef<'a> {
98 fn into_test_id(self) -> TestIdRef<'a> {
99 self
100 }
101}
102
103impl<T: TestId> IntoTestId<'_> for T {
104 fn into_test_id(self) -> TestIdRef<'static> {
105 TestIdRef {
106 id: self.test_id(),
107 rust_path: Some(self.rust_path()),
108 }
109 }
110
111 fn qualified_rust_path(&self) -> Option<&'static str> {
112 Some(self.qualified_path())
113 }
114}