fork(1) download
  1. use std::str::FromStr;
  2.  
  3. impl<A:FromStr,B:FromStr> FromStr for (A,B) {
  4. type Err = String;
  5. fn from_str(s: &str) -> Result<Self,Self::Err> {
  6. let mut xs = s.split_whitespace();
  7. Ok((xs.next().unwrap().parse().ok().unwrap(),
  8. xs.next().unwrap().parse().ok().unwrap()))
  9. }
  10. }
  11.  
  12. fn main() {
  13. let s = "3 4";
  14.  
  15. let (a, b): (i32, i32) = s.parse().unwrap();
  16.  
  17. println!("{:?} {:?}", a, b);
  18.  
  19. }
  20.  
  21.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
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
Standard output is empty