[OT] Some neat ideas from the Kotlin language
rsw0x via Digitalmars-d
digitalmars-d at puremagic.com
Tue Feb 23 11:43:43 PST 2016
On Tuesday, 23 February 2016 at 14:58:21 UTC, Xinok wrote:
> 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
How does this differ from the example I gave where the branch is
only taken if the pointer is non-null?
More information about the Digitalmars-d
mailing list