rust-lang/project-deref-patterns

`deref` on `Box<str>`

AlbertMarashi opened this issue · 2 comments

reposted:

I have this code, it does not compile. I am trying to deeply match a Box inside of a pattern, but the error is:

expected str, found `&str`

but there's no good way to match Box in a deeply nested pattern...

#![feature(box_patterns)]
struct Type {
    pub name: Box<str>,
    pub generics: Option<Vec<Type>>
}

fn main(){
    let kind = Type {
        name: "User".into(),
        generics: Some(Vec::new())
    };

    match kind {
        Type {
            name: box "User",
            generics
        } => {}
        _ => unimplemented!()
    }
}

Is there any kind of proposal to address the deref for this specific case?

Box is planned to be covered by the initial version of deref patterns, regardless of the inner type.

Great to hear. Can't wait for this feature. Any idea as to how long this process usually takes?