diff --git a/rustler/src/dynamic.rs b/rustler/src/dynamic.rs index 0a3996f0..47e89176 100644 --- a/rustler/src/dynamic.rs +++ b/rustler/src/dynamic.rs @@ -1,5 +1,10 @@ #[cfg(feature = "nif_version_2_15")] -use rustler_sys::ErlNifTermType; +use rustler_sys::{ + ErlNifTermType, ERL_NIF_TERM_TYPE_ATOM, ERL_NIF_TERM_TYPE_BITSTRING, ERL_NIF_TERM_TYPE_FLOAT, + ERL_NIF_TERM_TYPE_FUN, ERL_NIF_TERM_TYPE_INTEGER, ERL_NIF_TERM_TYPE_LIST, + ERL_NIF_TERM_TYPE_MAP, ERL_NIF_TERM_TYPE_PID, ERL_NIF_TERM_TYPE_PORT, + ERL_NIF_TERM_TYPE_REFERENCE, ERL_NIF_TERM_TYPE_TUPLE, +}; use crate::wrapper::check; use crate::Term; @@ -23,7 +28,6 @@ pub enum TermType { #[cfg(feature = "nif_version_2_15")] impl From for TermType { fn from(term_type: ErlNifTermType) -> Self { - use ErlNifTermType::*; use TermType::*; match term_type { ERL_NIF_TERM_TYPE_ATOM => Atom, diff --git a/rustler_sys/src/rustler_sys_api.rs b/rustler_sys/src/rustler_sys_api.rs index ab15827b..50abaad8 100644 --- a/rustler_sys/src/rustler_sys_api.rs +++ b/rustler_sys/src/rustler_sys_api.rs @@ -308,28 +308,39 @@ pub enum ErlNifHash { /// See [ErlNifTermType](http://www.erlang.org/doc/man/erl_nif.html#ErlNifTermType) in the Erlang docs. #[cfg(feature = "nif_version_2_15")] -#[derive(Copy, Clone)] -#[repr(C)] -pub enum ErlNifTermType { - // from https://github.com/erlang/otp/blob/6618ce7b6a621e92db72ea4f01f7d38553c8818c/erts/emulator/beam/erl_nif.h#L291 - ERL_NIF_TERM_TYPE_ATOM = 1, - ERL_NIF_TERM_TYPE_BITSTRING = 2, - ERL_NIF_TERM_TYPE_FLOAT = 3, - ERL_NIF_TERM_TYPE_FUN = 4, - ERL_NIF_TERM_TYPE_INTEGER = 5, - ERL_NIF_TERM_TYPE_LIST = 6, - ERL_NIF_TERM_TYPE_MAP = 7, - ERL_NIF_TERM_TYPE_PID = 8, - ERL_NIF_TERM_TYPE_PORT = 9, - ERL_NIF_TERM_TYPE_REFERENCE = 10, - ERL_NIF_TERM_TYPE_TUPLE = 11, - - /* This is a dummy value intended to coax the compiler into warning about - * unhandled values in a switch even if all the above values have been - * handled. We can add new entries at any time so the user must always - * have a default case. */ - ERL_NIF_TERM_TYPE__MISSING_DEFAULT_CASE__READ_THE_MANUAL = -1, -} +pub type ErlNifTermType = c_int; + +// from https://github.com/erlang/otp/blob/6618ce7b6a621e92db72ea4f01f7d38553c8818c/erts/emulator/beam/erl_nif.h#L291 +#[cfg(feature = "nif_version_2_15")] +pub const ERL_NIF_TERM_TYPE_ATOM: ErlNifTermType = 1; +#[cfg(feature = "nif_version_2_15")] +pub const ERL_NIF_TERM_TYPE_BITSTRING: ErlNifTermType = 2; +#[cfg(feature = "nif_version_2_15")] +pub const ERL_NIF_TERM_TYPE_FLOAT: ErlNifTermType = 3; +#[cfg(feature = "nif_version_2_15")] +pub const ERL_NIF_TERM_TYPE_FUN: ErlNifTermType = 4; +#[cfg(feature = "nif_version_2_15")] +pub const ERL_NIF_TERM_TYPE_INTEGER: ErlNifTermType = 5; +#[cfg(feature = "nif_version_2_15")] +pub const ERL_NIF_TERM_TYPE_LIST: ErlNifTermType = 6; +#[cfg(feature = "nif_version_2_15")] +pub const ERL_NIF_TERM_TYPE_MAP: ErlNifTermType = 7; +#[cfg(feature = "nif_version_2_15")] +pub const ERL_NIF_TERM_TYPE_PID: ErlNifTermType = 8; +#[cfg(feature = "nif_version_2_15")] +pub const ERL_NIF_TERM_TYPE_PORT: ErlNifTermType = 9; +#[cfg(feature = "nif_version_2_15")] +pub const ERL_NIF_TERM_TYPE_REFERENCE: ErlNifTermType = 10; +#[cfg(feature = "nif_version_2_15")] +pub const ERL_NIF_TERM_TYPE_TUPLE: ErlNifTermType = 11; + +/* This is a dummy value intended to coax the compiler into warning about + * unhandled values in a switch even if all the above values have been + * handled. We can add new entries at any time so the user must always + * have a default case. */ +#[allow(non_upper_case_globals)] +#[cfg(feature = "nif_version_2_15")] +pub const ERL_NIF_TERM_TYPE__MISSING_DEFAULT_CASE__READ_THE_MANUAL: ErlNifTermType = -1; /// See [ErlNifOption](http://www.erlang.org/doc/man/erl_nif.html#ErlNifOption) in the Erlang docs. #[cfg(feature = "nif_version_2_17")]