On Fri, Oct 19, 2012 at 8:43 AM, John Mija <[email protected]> wrote:
> Rust has attributes[1] at function-level but (1) the compilation could
> be faster if they were at file-level, and (2) the project would be more
> homogeneous and clean.
>
> + Instead of to have the attribute "#[test]" for a function, those tests
> functions could be into a file with the name finished in "_test"
> (foo_test.rs) indicating that there are unit tests. On this case, we
> would not need an attribute.
>
> + Instead of to have conditionally-compiled modules at function level,
> that code could be into a file finished in the system name
> (foo_linux.rs), and/or use attributes at file level. See how Go solved
> this problem, in Build constraints[2].
>
> + Instead of to have an attribute for the documentation, the parser
> could get the comment on top of the function to get its documentation.
>
> Now:
>
>   // A documentation attribute
>   #[doc = "Add two numbers together."]
>   fn add(x: int, y: int) { x + y }
>
> Proposal:
>
>   // add adds two numbers together."
>   fn add(x: int, y: int) { x + y }

There are very good reasons for having attributes at a lower level
than file (test autodiscovery, when you want something more reliable
than an easily mistyped convention, automated dependency injection,
marking transactional methods...). Of course, a lot of this would need
rust's attributes to be usable outside of the compiler (as opposed to
a handful of hardcoded elements), but I hope we'll have this in the
near future (hint hint).

Cheers,

Emm
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to