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

Feature request: assert_expr_impl! #14

Open
scottjmaddox opened this issue Jun 18, 2019 · 3 comments
Open

Feature request: assert_expr_impl! #14

scottjmaddox opened this issue Jun 18, 2019 · 3 comments

Comments

@scottjmaddox
Copy link

scottjmaddox commented Jun 18, 2019

Over on the rust internals board, betamos noted that it would be nice to be able to annotate a type or value as sendable, and get a compile-time error if it is not. I thought this should be achievable using a macro, and that it would be a good fit for this crate. Maybe someone here can take a crack at it?

Edit: updated request to assert_expr_impl!

@nvzqz
Copy link
Owner

nvzqz commented Jun 18, 2019

Is this not already achievable with assert_impl!(Type, Send)? However, reading the comment by @betamos, it seems they want to assert that an expression is sendable. In which case, I guess an assert_expr_impl! macro would be needed.

@scottjmaddox
Copy link
Author

I actually didn't know about assert_impl!! So yeah, that covers the type assertion! But it would also be nice to have an expression assertion.

@scottjmaddox scottjmaddox changed the title Feature request: assert_sendable! Feature request: assert_expr_impl! Jun 18, 2019
@leo60228
Copy link

leo60228 commented Nov 7, 2019

macro_rules! assert_expr_impl_all {
    ($expr:expr => $($trait:path),+ $(,)?) => {
        const _: fn() = || {
            // Only callable when `$type` implements all traits in `$($trait)+`.
            fn assert_expr_impl_all<T: ?Sized $(+ $trait)+>(_arg: &T) {}
            assert_expr_impl_all(&$expr);
        };
    };
}

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

No branches or pull requests

3 participants