Skip to content

Commit 9405adf

Browse files
committed
Add type hint struct
1 parent 1450e71 commit 9405adf

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

src/libstd/util.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,23 @@ impl Void {
8080
}
8181
}
8282

83+
/// A zero-sized type hint useful for accessing static methods that don't
84+
/// mention `Self`.
85+
///
86+
/// # Example
87+
///
88+
/// ~~~rust
89+
/// trait A {
90+
/// fn a(_: ForType<Self>) -> uint;
91+
/// }
92+
///
93+
/// impl A for int {
94+
/// fn a(_: ForType<Self>) -> uint { 6 }
95+
/// }
96+
///
97+
/// assert_eq!(A::a(ForType::<int>), 6);
98+
/// ~~~
99+
pub struct ForType<T>;
83100

84101
#[cfg(test)]
85102
mod tests {
@@ -151,6 +168,19 @@ mod tests {
151168

152169
unsafe { assert_eq!(did_run, true); }
153170
}
171+
172+
#[test]
173+
fn type_hint() {
174+
trait A {
175+
fn a(_: ForType<Self>) -> uint;
176+
}
177+
178+
impl A for int {
179+
fn a(_: ForType<Self>) -> uint { 6 }
180+
}
181+
182+
assert_eq!(A::a(ForType::<int>), 6);
183+
}
154184
}
155185

156186
/// Completely miscellaneous language-construct benchmarks.

0 commit comments

Comments
 (0)