News for hackers. Stuff that matters.
Re:Why your first Rust FizzBuzz implementation may not work by kibwen on Monday October 13, 2014 @12:10AM (#8447446)
I don't think a common ancestor is how you want to do this. Instead, I'd encapsulate the common behavior in a trait (a.k.a. an interface, in other languages), and then write functions that accept any parameters that implement that trait. In Rust, you can do this even on "built-in" types like strings. For an example, see the `print_me` function below, which operates on both string types using a trait that I've defined myself.

  trait WhatIsThis {
      fn what_is_this(self);
  }

  impl WhatIsThis for String {
      fn what_is_this(self) {
          println!("'{:s}' is a string!", self);
      }
  }

  impl WhatIsThis for &'static str {
      fn what_is_this(self) {
          println!("'{:s}' is a string slice!", self);
      }
  }

  fn print_me<T>(me: T) where T: WhatIsThis {
      me.what_is_this();
  }

  fn main() {
      print_me("Blah blah blah");
      print_me("Yada yada yada".to_string());
  }
Re:Why your first Rust FizzBuzz implementation may not work by wycats on Monday October 13, 2014 @12:34AM (#8447494)
And I expect virtually all of the methods on slice to be available on String before long. I think it's a bug that this isn't the case today.

It's already possible to have a function take "either a String or slice" generically:

    def print_me<T>(me: T) where T: Str {
        println!("I am '{:s}'", me.as_slice());
    }
The overall ergonomics of this (or at least, the well-documented idioms) will certainly improve in the coming months.
Re:Why your first Rust FizzBuzz implementation may not work by steveklabnik on Monday October 13, 2014 @02:38AM (#8447717)