Some notes on Rust

Paulo Pinto via Digitalmars-d digitalmars-d at puremagic.com
Sat Feb 7 16:08:50 PST 2015


On Saturday, 7 February 2015 at 23:52:04 UTC, Andrei Alexandrescu 
wrote:
> On 2/7/15 3:46 PM, Paulo Pinto wrote:
>> Any attempt to assign anything outside 0..64 range to Size will
>> trigger an error, either at compile or run-time.
>
> What would be the similarities and differences of this built-in 
> feature with traditional encapsulation using e.g. a C++ class? 
> Thanks! -- Andrei

For starters you don't need to do anything more than the type 
statement.

With C++ someone needs to write the class, overload the set of 
operators that apply to the type, including copy and move 
operations/constructors.

Compile time validation can only be done maybe with C++14 
constexpr.

Probably with clever template metaprogramming some of that code 
can be generated, but we all know how average developers like the 
error messages.

So basically the difference between declaring a class in C++, or 
doing OOP by hand in C.

Sometimes it is better to leave the hard work for the compiler.

--
Paulo


More information about the Digitalmars-d mailing list