Range syntax is confusing

I'm honestly not sure what would lead you to that conclusion? Patterns in general do not move the thing they match against unless strictly necessary. (ident patterns, enum patterns that contain an ident pattern that moves something, and probably some other funny edge cases)

Look, you can even partially move out of a struct with a struct pattern:

struct Struct {
    a: Vec<()>,
    b: Vec<()>,
}

fn main() {
    let x = Struct { a: vec![], b: vec![] };
    match x {
        Struct { a, .. } => {},
    };
    x.b; // still valid; only x.a could have been moved
}

Heck, you can even do it from within a Box:

fn main() {
    let x = Box::new(Struct { a: vec![], b: vec![] });
    match *x {
        Struct { a, .. } => {},
    };
    x.b; // still valid; only x.a was moved
}

(that's a bit surprising actually!)

4 Likes

Well, Box<T> is pretty special :grinning:

6 Likes

A post was split to a new topic: Disabling typographer auto-fixups

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.