use std:: str :: FromStr ;
impl< A: FromStr, B: FromStr> FromStr for ( A, B) {
type Err = String;
fn from_str( s: & str) -> Result< Self, Self:: Err > {
let mut xs = s.split_whitespace ( ) ;
Ok( ( xs.next ( ) .unwrap ( ) .parse ( ) .ok ( ) .unwrap ( ) ,
xs.next ( ) .unwrap ( ) .parse ( ) .ok ( ) .unwrap ( ) ) )
}
}
fn main( ) {
let s = "3 4" ;
let ( a, b) : ( i32, i32) = s.parse ( ) .unwrap ( ) ;
println! ( "{:?} {:?}" , a, b) ;
}
dXNlIHN0ZDo6c3RyOjpGcm9tU3RyOwoKaW1wbDxBOkZyb21TdHIsQjpGcm9tU3RyPiBGcm9tU3RyIGZvciAoQSxCKSB7CiAgICB0eXBlIEVyciA9IFN0cmluZzsKICAgIGZuIGZyb21fc3RyKHM6ICZzdHIpIC0+IFJlc3VsdDxTZWxmLFNlbGY6OkVycj4gewogICAgICAgIGxldCBtdXQgeHMgPSBzLnNwbGl0X3doaXRlc3BhY2UoKTsKICAgICAgICBPaygoeHMubmV4dCgpLnVud3JhcCgpLnBhcnNlKCkub2soKS51bndyYXAoKSwKICAgICAgICAgICAgeHMubmV4dCgpLnVud3JhcCgpLnBhcnNlKCkub2soKS51bndyYXAoKSkpCiAgICB9Cn0KCmZuIG1haW4oKSB7CiAgICBsZXQgcyA9ICIzIDQiOwogICAgCiAgICBsZXQgKGEsIGIpOiAoaTMyLCBpMzIpID0gcy5wYXJzZSgpLnVud3JhcCgpOwogICAgICAgIAogICAgcHJpbnRsbiEoIns6P30gezo/fSIsIGEsIGIpOwogICAgCn0KCg==
compilation info
error[E0210]: type parameter `A` must be used as the type parameter for some local type (e.g. `MyStruct<T>`); only traits defined in the current crate can be implemented for a type parameter
--> prog.rs:3:1
|
3 | impl<A:FromStr,B:FromStr> FromStr for (A,B) {
| ^
error: aborting due to previous error
stdout