[OT] Some neat ideas from the Kotlin language
Xinok via Digitalmars-d
digitalmars-d at puremagic.com
Tue Feb 23 06:58:21 PST 2016
On Tuesday, 23 February 2016 at 07:18:09 UTC, rsw0x wrote:
> On Tuesday, 23 February 2016 at 06:49:46 UTC, Tobias Müller
> wrote:
>> OTOH in the examples in Kotlin/Rust the variable 'var' changes
>> its type
>> from 'int?' to plain 'int'.
>> In Kotlin this is done with static analysis, in Rust with
>> rebinding of the
>> name.
>>
>> Tobi
>
> Rust's Option<T> checks are not done at compile-time in most
> cases unless something changed drastically in the past ~18
> months.
Option<T> is an enum type in Rust (i.e. algebraic data type). The
Rust compiler forces you to check all possible cases so you can't
use it improperly. So you would have to use something like
pattern matching or "if let" to check the state.
https://doc.rust-lang.org/book/match.html#matching-on-enums
More information about the Digitalmars-d
mailing list