Slice patterns in Nightly Rust

Tobias Müller via Digitalmars-d digitalmars-d at puremagic.com
Sun Jun 21 02:55:05 PDT 2015


"Nicholas Wilson" <iamthewilsonator at hotmail.com> wrote:
> On Sunday, 21 June 2015 at 03:23:18 UTC, Dennis Ritchie wrote:
>> Recently published documentation Nightly Rust. I saw this:
>> https://doc.rust-lang.org/nightly/book/slice-patterns.html
>> 
>> What do you think about this: a terrible thing or a cool > feature?
>> 
>> fn is_symmetric(list: &[u32]) -> bool {
>>     match list {
>>         [] | [_] => true,
>>         [x, inside.., y] if x == y => is_symmetric(inside),
>>         _ => false
>>     }
>> } 
> [...]
> Also implicit declaration of variables. Urgh.

Patterns are the way that variables are declared in Rust, there's nothing
implicit about that.

let <pattern> = <expr>;

match <expr>
{
    <pattern> = <expr>,
    <pattern> = <expr>,
}

fn myfunction(<pattern>, <pattern>)

And AFAIK those are the only places where patterns appear and where
variables are declared.

Tobi


More information about the Digitalmars-d mailing list