[rust-dev] Naming conventions for constructors

Brian Anderson banderson at mozilla.com
Tue Aug 14 18:24:05 PDT 2012


On 08/14/2012 06:04 PM, Erick Tryzelaar wrote:
> On Tue, Aug 14, 2012 at 4:35 PM, Brian Anderson <banderson at mozilla.com> wrote:
>> Hey.
>
> Hello.
>
> :)
>
>> Then to use it:
>>
>>      import my_crate::belt_buckle;
>>
>>      let my_belt_buckle = belt_buckle::new();
>>
>> You will mostly not import the constructor because it will need to be
>> disambiguated from all the other 'new's in the world.
>
>
> This is fine with me, I liked this style back in the pre-typeclass
> rust. There were two things that bugged me about this style. First,
> impls made import lines pretty dense, so it was nice to just import
> one type/impl/fn. Is this still the case with the new min/max classes?

The situation is much better with impls now. Any impls defined in the 
same module as the type are automatically available everywhere. The 
current scheme is nice in that you import `dvec::dvec` and get both the 
type and the constructor.

> Second, If I wanted to import anything from the module, I'd have to
> write:
>
> import my_crate::belt_buckle;
> import my_crate::belt_buckle::BeltBuckle;
>
>
> Maybe we could add some sugar to combine those two lines into (forgive
> me if there's already a way to do this):
>
> import my_crate::belt_buckle::{., BeltBuckle};
>

Something like this does seem appropriate.



More information about the Rust-dev mailing list