]> git.proxmox.com Git - rustc.git/blob - tests/ui/statics/auxiliary/static-methods-crate.rs
New upstream version 1.68.2+dfsg1
[rustc.git] / tests / ui / statics / auxiliary / static-methods-crate.rs
1 #![crate_name="static_methods_crate"]
2 #![crate_type = "lib"]
3
4 pub trait read: Sized {
5 fn readMaybe(s: String) -> Option<Self>;
6 }
7
8 impl read for isize {
9 fn readMaybe(s: String) -> Option<isize> {
10 s.parse().ok()
11 }
12 }
13
14 impl read for bool {
15 fn readMaybe(s: String) -> Option<bool> {
16 match &*s {
17 "true" => Some(true),
18 "false" => Some(false),
19 _ => None
20 }
21 }
22 }
23
24 pub fn read<T:read>(s: String) -> T {
25 match read::readMaybe(s) {
26 Some(x) => x,
27 _ => panic!("read panicked!")
28 }
29 }