Macro nix::macros::libc_enum

source ·
macro_rules! libc_enum {
    (@make_enum
        name: $BitFlags:ident,
        {
            $v:vis
            attrs: [$($attrs:tt)*],
            entries: [$($entries:tt)*],
        }
    ) => { ... };
    (@make_enum
        name: $BitFlags:ident,
        {
            $v:vis
            attrs: [$($attrs:tt)*],
            entries: [$($entries:tt)*],
            from_type: $repr:path,
            try_froms: [$($try_froms:tt)*]
        }
    ) => { ... };
    (@accumulate_entries
        name: $BitFlags:ident,
        {
            $v:vis
            attrs: $attrs:tt,
        },
        $entries:tt,
        $try_froms:tt;
    ) => { ... };
    (@accumulate_entries
        name: $BitFlags:ident,
        {
            $v:vis
            attrs: $attrs:tt,
            from_type: $repr:path,
        },
        $entries:tt,
        $try_froms:tt;
    ) => { ... };
    (@accumulate_entries
        name: $BitFlags:ident,
        $prefix:tt,
        [$($entries:tt)*],
        [$($try_froms:tt)*];
        #[$attr:meta] $($tail:tt)*
    ) => { ... };
    (@accumulate_entries
        name: $BitFlags:ident,
        $prefix:tt,
        [$($entries:tt)*],
        [$($try_froms:tt)*];
        $entry:ident
    ) => { ... };
    (@accumulate_entries
        name: $BitFlags:ident,
        $prefix:tt,
        [$($entries:tt)*],
        [$($try_froms:tt)*];
        $entry:ident,
        $($tail:tt)*
    ) => { ... };
    (@accumulate_entries
        name: $BitFlags:ident,
        $prefix:tt,
        [$($entries:tt)*],
        [$($try_froms:tt)*];
        $entry:ident as $ty:ty,
        $($tail:tt)*
    ) => { ... };
    (
        $(#[$attr:meta])*
        $v:vis enum $BitFlags:ident {
            $($vals:tt)*
        }
    ) => { ... };
    (
        $(#[$attr:meta])*
        $v:vis enum $BitFlags:ident {
            $($vals:tt)*
        }
        impl TryFrom<$repr:path>
    ) => { ... };
}
Expand description

The libc_enum! macro helps with a common use case of defining an enum exclusively using values from the libc crate. This macro supports both pub and private enums.

The libc crate must be in scope with the name libc.

§Example

libc_enum!{
    pub enum ProtFlags {
        PROT_NONE,
        PROT_READ,
        PROT_WRITE,
        PROT_EXEC,
        #[cfg(linux_android)]
        PROT_GROWSDOWN,
        #[cfg(linux_android)]
        PROT_GROWSUP,
    }
}