Arc::new(Mutex::new(0u32)) -> Arc(Mutex(0u32))

Maybe this has been discussed before but I want to suggest using same constructor syntax as used in enums and unit structs for normal structs to call a default constructor (new()?) to reduce clutter.

As can be seen in the topic, looks much nicer, easier to type and easy to understand that a default constructor is been called.

What do you think?

Not a fan: those types are not just the data being wrapped inside. This form calls enums and tuple structs to mind, which Arc and Mutex very definitely are not.

To put it another way: this implies a simplicity those types don’t possess; it’s misleading.

Edit: plus, it would imply you can destructure those types, which you also can’t.

There was actually a debate about doing this before 1.0, but it’s surely too late to consider changing the convention now.

rustc appears to like to do this, P(x), FnvHashMap() and so on. Libraries will have to think over this on a case by case basis, I think it’s good that there is a way to emulate the newtype construction syntax.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.