Skip to content

Blacklisting enum/const #1526

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

Closed
jeikabu opened this issue Feb 27, 2019 · 1 comment
Closed

Blacklisting enum/const #1526

jeikabu opened this issue Feb 27, 2019 · 1 comment

Comments

@jeikabu
Copy link

jeikabu commented Feb 27, 2019

Expected to be able to exclude an enum value that is defined, but not part of the external API.
Suspect this may be intentional for the same reason the docs mention this issue.

Input C/C++ Header

typedef enum {
	NNG_PIPE_EV_ADD_PRE,  // Called just before pipe added to socket
	NNG_PIPE_EV_ADD_POST, // Called just after pipe added to socket
	NNG_PIPE_EV_REM_POST, // Called just after pipe removed from socket
	NNG_PIPE_EV_NUM,      // Used internally, must be last.
} nng_pipe_ev;

Bindgen Invocation

let mut builder = bindgen::Builder::default()
            .header("src/wrapper.h")
            .blacklist_item("NNG_PIPE_EV_NUM") // Only used to bounds-check nng_pipe_ev
            .blacklist_item("nng_pipe_ev_NNG_PIPE_EV_NUM");
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
        builder
            .generate()
            .expect("Unable to generate bindings")
            .write_to_file(out_path.join("bindings.rs"))
            .expect("Couldn't write bindings");

Tried several variants with/without:

.prepend_enum_name(true)
// And/or
.default_enum_style(bindgen::EnumVariation::Rust)

Actual Results

pub const nng_pipe_ev_NNG_PIPE_EV_ADD_PRE: nng_pipe_ev = 0;
pub const nng_pipe_ev_NNG_PIPE_EV_ADD_POST: nng_pipe_ev = 1;
pub const nng_pipe_ev_NNG_PIPE_EV_REM_POST: nng_pipe_ev = 2;
pub const nng_pipe_ev_NNG_PIPE_EV_NUM: nng_pipe_ev = 3;
// or
#[repr(u32)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub enum nng_pipe_ev {
    NNG_PIPE_EV_ADD_PRE = 0,
    NNG_PIPE_EV_ADD_POST = 1,
    NNG_PIPE_EV_REM_POST = 2,
    NNG_PIPE_EV_NUM = 3,
}

Expected Results

pub const nng_pipe_ev_NNG_PIPE_EV_ADD_PRE: nng_pipe_ev = 0;
pub const nng_pipe_ev_NNG_PIPE_EV_ADD_POST: nng_pipe_ev = 1;
pub const nng_pipe_ev_NNG_PIPE_EV_REM_POST: nng_pipe_ev = 2;
// or
#[repr(u32)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub enum nng_pipe_ev {
    NNG_PIPE_EV_ADD_PRE = 0,
    NNG_PIPE_EV_ADD_POST = 1,
    NNG_PIPE_EV_REM_POST = 2,
}
@emilio
Copy link
Contributor

emilio commented Feb 27, 2019

You can hide enum variants themselves. The reason why blacklist_item doesn't work is because a variant is not an item itself.

You can customize enum variant behavior via:

https://docs.rs/bindgen/0.47.3/bindgen/callbacks/trait.ParseCallbacks.html#method.enum_variant_behavior

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

2 participants