Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to match Boxed value? #554

Open
shiqicao opened this issue Dec 25, 2024 · 0 comments
Open

How to match Boxed value? #554

shiqicao opened this issue Dec 25, 2024 · 0 comments

Comments

@shiqicao
Copy link

shiqicao commented Dec 25, 2024

Is there a way to match Box<T>, where T doesn't implement Copy?

        #[derive(Debug)]
        struct A(Box<B>);

        #[derive(Debug)]
        struct B(usize);

        let a = A(Box::new(B(1usize)));
   
        type BoxB = Box<B>;

        expect_that!(a, pat! (A( result_of_ref!(|x: &BoxB| x.as_ref(), pat!(&B(eq(&1usize)))))));

Got error,

error: lifetime may not live long enough
   --> crates/pota_parser/src/parser/mod.rs:716:60
    |
716 |         expect_that!(a, pat! (A( result_of_ref!(|x: &BoxB| x.as_ref(), pat!(&B(eq(&1usize)))))));
    |                                                     -    - ^^^^^^^^^^ returning this value requires that `'1` must outlive `'2`
    |                                                     |    |
    |                                                     |    return type of closure is &'2 B
    |                                                     let's call the lifetime of this reference `'1`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant