The closest variant can be implemented by using enums, but I can't say that
resulted code is nice.:

enum foo_param {
    i(int),
    s(str)
}

fn foo(param: foo_param) {
    alt param {
        i(int_val) {
            io::println(#fmt("foo was called with int == %d", int_val));
        }
        s(str_val) {
            io::println(#fmt("foo was called with str == %s", str_val));
        }
    }
}

fn main() {
    foo(i(10));
    foo(s("test"));
}


Not only that, but it adds an extra layer of complexity for type
> inferencing, which quite frankly is already complex enough.
>
> That said, you can do a limited form of overloading using impls:
>
> impl methods for int {
>    fn foo() { ... }
> }
>
> impl methods for uint {
>    fn foo() { ... }
> }
>
>
>
>
> Niko
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to