#[ffi_enum]Expand description
Converts the enum into ffi-safe enums that could be safely sent through ffi Metadata, separated with
,, passed as arguments of this attribute call would be transformed into raw attributes attached on
the generated ffi_enum.
The generated ffi_enum type implements ::ffi_enum::FfiEnum that provides with essential type and constant
informations of the generated details.
The generated ffi_enum type by default implements Copy, Clone, PartialEq, Eq, based on which
essential implementations could be derived.
ยงFor Derive Macros
There are 3 positions to place derive macros:
-
(Preferred)
#[derive(...)]attached aboveffi_enumwould see the originalenumdefinition andimpls for the generatedffi_enumtype. Note that helper attributes attached below thisffi_enumattribute would also be seen by such derive macros. -
#[ffi_enum(derive(...))]passed within this attribute would both see the definition of and takes all effects on the generatedffi_enumtype. All helper attributes passed within this attribute would only be been by the derive macros passed in this way. -
#[derive(...)]attached belowffi_enumwould both see the definition of and takes all effects on the the originalenumdefinition.
Derive macros that works on regular enums may simply works fine at Position 1 described above,
unless the expanded code matches the value of the generated ffi_enum type without a
_ wildcard pattern that covers other unknown values that would potentially come from ffi.
As for the derive macros that does not care the variant details, or normally logically works fine for a
struct that contaions a single field, attach the derive macros along with
their helper attributes at Position 2. Derive macros passed in this way would see a ffi_enum_origin
helper attribute with the original enum definition passed as the arguments. If you are authoring a derive
macro that may need to see both the original and generated definitions, this way is preferred.
As for the derive macros that generate matching code without wildcards, or the implemention of which is
logically insufficient for the generated ffi_enum type that covers all binary patterns. The only
way of automatic deriving is to derive at Position 3 described above, which implements for the original
enum definition, and then delegate the implementations from the original enum definition which could
accessed as <TypeName as ffi_enum::FfiEnum>::Enum.
This attribute macro would automatically delegate implementations for the generated ffi_enum type
for supported traits. The currently supported derives are:
core::fmt::Debugcore::fmt::Display(The derive macro for the originalenumis not hereby specified, user may use any one that implements it for the original type)core::hash::Hashcore::str::FromStr(The derive macro for the originalenumis not hereby specified, user may use any one that implements it for the original type)thiserror::Errorimplementingcore::error::Errorandcore::fmt::Displayserde::Serializeserde::Deserialize
For more automatically delegatings, contributions are welcomed.