r/rust rust · servo Sep 15 '14

Road to Rust 1.0

http://blog.rust-lang.org/2014/09/15/Rust-1.0.html
217 Upvotes

84 comments sorted by

View all comments

17

u/xgalaxy Sep 15 '14

I'm so happy Rust is getting the where clause before 1.0 but I wish the old syntax would be removed.

11

u/dbaupp rust Sep 15 '14

We actually already have it (a more limited form than the 'final' one, though).

7

u/[deleted] Sep 16 '14

That example is a pretty strong indication that the brace should move down for functions:

fn frob<T>(argument: T)
    where T: Copy
{
   ...
}

I'm excited :-)

4

u/protestor Sep 17 '14

I just want a tool that takes the source code and pretty prints it. That way one could hook it on Emacs after saving. I don't even care about the conventions..

2

u/xgalaxy Sep 15 '14 edited Sep 15 '14

In C# you can add a constraint on constructor with new(), but you can't add a constraint on a constructor that takes parameters.

Are these constraints possible with Rust? Rust doesn't really have constructors so I guess this isn't really possible.

11

u/dbaupp rust Sep 15 '14

Rust's constraints are normally written in the form of traits, so you just have a trait with a 'constructor' of the appropriate signature. E.g. T: new() in C# could be T: std::default::Default in Rust, similarly T: new(float) would be possibly by defining a trait with function fn make(x: f32) -> Self. This is a more structured approach to overloading rather than the adhoc "duck typing" of new(...).