On Sun, Aug 26, 2012 at 6:33 PM, Steve Jenson <[email protected]> wrote:
> Hi rustics,
>
> I spent some time this weekend going over the rust tutorial and
> documentation for 0.3.1. I thought a fun exercise would be writing an
> xUnit testing framework[1] in a "classic" OO style. I ran into a few
> problems:
>
> 1) xUnit historically relies on inheritance but it's not clear to me
> how to model an is-a relationship in Rust. For instance, define an
> abstract base class (TestSuite) and an implementation that tests a set
> of functions (say, a calculator).
>

Hi, Steve --

The way to do this in Rust would be to define a trait TestSuite, and
impls that implement that trait for various types. Patrick's tutorial
should be helpful:

http://pcwalton.github.com/blog/2012/08/08/a-gentle-introduction-to-traits-in-rust/


> 2) How to colocate state and behavior in impls. Embedding lets in my
> impls results in errors.

impls don't talk about state, and we don't have plans to change that
as far as I know. As shown in Patrick's tutorial, you define all your
fields in struct definitions, and then provide impls that implement
various traits for a particular struct. This doesn't preclude
anything: you can always define methods on a struct that get/set its
fields.

>
> 3) Reflection. I have no documented way to iterate over the functions
> in an impl and call them. (I'm sure this is on the way and I'm just
> early to the party)
>

I don't know of any plans to do this. I'm not sure why you would want
to; if you can give an example, it might help.

> I also think I'm approaching this from the wrong direction and that
> Rust's OO with typeclasses are different from how I'm using to
> building software in another language with typeclasses (Scala). I'm
> still looking for the zen of Rust OO.
>
> I ran into some old blog posts that discuss a class keyword but I
> wasn't able to make those examples run in 0.3.1. Do we only have impls
> now?

The class keyword is deprecated; struct replaces class.

Feel free to ask again if you have more questions (or visit #rust on IRC).

Cheers,
Tim

-- 
Tim Chevalier * http://catamorphism.org/ * Often in error, never in doubt
"Debate is useless when one participant denies the full dignity of the
other." -- Eric Berndt
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to