corollary icon indicating copy to clipboard operation
corollary copied to clipboard

How can you match on an empty array?

Open tcr opened this issue 8 years ago • 3 comments

Say we're matching:

case value of 
    Container([]) => ...,
    Container(vector) => ...,

This won't work in Rust if you try to match against a container. Unless box [] pattern works. Does this need an extensive AST transform to work?

tcr avatar May 23 '17 03:05 tcr

Would slice patterns in nightly rustc work? https://doc.rust-lang.org/book/slice-patterns.html

jdm avatar May 23 '17 05:05 jdm

Alternatively, use a pattern guard in a match?

jdm avatar May 23 '17 05:05 jdm

Pattern guards are a good choice here, I think the pattern is just [] and non_empty_vec throughout the code!

Slice patterns would work, though only at the top-level. Pattern matching against Vectors and Strings is not possible unless they're converted into boxed objects first (and box_patterns is enabled), so I should get more data on how they're used.

tcr avatar May 23 '17 23:05 tcr