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

#[cfg(...)] in the select macro #1085

Open
ogoffart opened this issue Feb 26, 2024 · 0 comments
Open

#[cfg(...)] in the select macro #1085

ogoffart opened this issue Feb 26, 2024 · 0 comments

Comments

@ogoffart
Copy link

It would be nice if it was possible to guard some arms with #[cfg] in the select macro.

For example: (based on the example of https://docs.rs/crossbeam/latest/crossbeam/macro.select.html#examples , but adding a channel2 feature )

use crossbeam_channel::{select, unbounded};

let (s1, r1) = unbounded();
#[cfg(feature = "channel2")]
let (s2, r2) = unbounded();
s1.send(10).unwrap();

// Since both operations are initially ready, a random one will be executed.
select! {
    recv(r1) -> msg => assert_eq!(msg, Ok(10)),
    #[cfg(feature = "channel2")]
    send(s2, 20) -> res => {
        assert_eq!(res, Ok(()));
        assert_eq!(r2.recv(), Ok(20));
    }
}

I know that the workaround is to use Select directly, but I'd thought this would be convenient and natural.

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

No branches or pull requests

2 participants