Guest User

rust generic impl error

a guest
Jan 29th, 2012
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1.  
  2. use std;
  3. import std::io::*;
  4.  
  5. iface ninja_str {
  6. fn to_str() -> str;
  7. }
  8.  
  9. impl of ninja_str for str {
  10. fn to_str() -> str { self }
  11. }
  12.  
  13. impl of ninja_str for [str] {
  14. fn to_str() -> str {
  15. alt vec::len(self) {
  16. 0u { "" }
  17. x {
  18. vec::foldl(self[0], vec::slice(self, 1u, x)) {|iter, y|
  19. iter + ", " + y
  20. }
  21. }
  22. }
  23. }
  24. }
  25.  
  26. // this works fine
  27. fn print<T: ninja_str>(str: T) {
  28. println(str.to_str());
  29. }
  30.  
  31. impl ninja_file for writer {
  32. // this causes 'error: internal error in instantiate'
  33. fn build<T: ninja_str>(str: T) {
  34. self.write(str::bytes(str.to_str()));
  35. }
  36. }
  37.  
  38. fn main() {
  39. //let n = result::get(mk_file_writer("build.ninja", [create]));
  40. //n.build("hello, world" as ninja_str);
  41. print("hello, world");
  42. }
Advertisement
Add Comment
Please, Sign In to add comment