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

*Flags don't implement set-like combinators #609

Open
cyphar opened this issue May 30, 2017 · 5 comments
Open

*Flags don't implement set-like combinators #609

cyphar opened this issue May 30, 2017 · 5 comments

Comments

@cyphar
Copy link

cyphar commented May 30, 2017

One thing I ran into almost immediately when trying to nicely define a set of flags like you would in C (with something like CLONE_NEWUSER|CLONE_NEWUTS|CLONE_NEWNS or whatever) is that you can't do it with the nix structs without declaring a variable mut and operating on it.

let mut sigmask = signal::SigSet::empty();
sigmask.add(signal::Signal::SIGTTOU);
sigmask.add(signal::Signal::SIGTTIN);
// etc

What if we made it so you could do this instead?

let sigmask = signal::SigSet::empty()
                             .add(signal::Signal::SIGTTOU)
                             .add(signal::Signal::SIGTTIN);

Which allows you to write it (IMO) more concisely but also doesn't mean that you have to make the variable mutable. It also better matches the Iterator combinators.

@Susurrus
Copy link
Contributor

You should be able to do

let sigmask = signal::Signal::SIGTTOU | signal::Signal::SIGTTIN;

Does that not work for you?

@posborne
Copy link
Member

posborne commented Jun 3, 2017

Closing as I'm assuming this meets or exceeds @cyphar's requirements.

@posborne posborne closed this as completed Jun 3, 2017
@cyphar
Copy link
Author

cyphar commented Jun 3, 2017

Sorry for not responding earlier. No, this code doesn't work:

   Compiling initrs v0.0.0 (file:///home/cyphar/.local/src/initrs)
error[E0369]: binary operation `|` cannot be applied to type `nix::sys::signal::Signal`
   --> src/main.rs:117:19
    |
117 |     let sigmask = signal::Signal::SIGTTOU | signal::Signal::SIGTTIN;
    |                   ^^^^^^^^^^^^^^^^^^^^^^^
    |
    = note: an implementation of `std::ops::BitOr` might be missing for `nix::sys::signal::Signal`

error: aborting due to previous error

error: Could not compile `initrs`.

My Cargo.toml:

[dependencies.nix]
version = "~0.8.1"
default-features = true
features = ["signalfd"]

@cyphar
Copy link
Author

cyphar commented Jun 3, 2017

But the solution would be to implement BitOr for SigSet and also implementing it for Signal such that it produces a SigSet.

@cyphar
Copy link
Author

cyphar commented Jun 3, 2017

I've implemented this in #615, as well as adding a From impl for SigSet::from(Signal).

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