Simplify enum_with_unknown! macro.

This commit is contained in:
whitequark 2021-03-12 06:02:04 +00:00
parent 4933a0a19f
commit 9f0213765c
9 changed files with 17 additions and 30 deletions

View File

@ -23,21 +23,8 @@ macro_rules! enum_with_unknown {
(
$( #[$enum_attr:meta] )*
pub enum $name:ident($ty:ty) {
$( $variant:ident = $value:expr ),+ $(,)*
}
) => {
enum_with_unknown! {
$( #[$enum_attr] )*
pub doc enum $name($ty) {
$( #[doc(shown)] $variant = $value ),+
}
}
};
(
$( #[$enum_attr:meta] )*
pub doc enum $name:ident($ty:ty) {
$(
$( #[$variant_attr:meta] )+
$( #[$variant_attr:meta] )*
$variant:ident = $value:expr $(,)*
),+
}

View File

@ -10,7 +10,7 @@ use crate::time::Instant;
enum_with_unknown! {
/// Captured packet header type.
pub doc enum PcapLinkType(u32) {
pub enum PcapLinkType(u32) {
/// Ethernet frames
Ethernet = 1,
/// IPv4 or IPv6 packets (depending on the version field)

View File

@ -8,7 +8,7 @@ use crate::wire::{Ipv4Packet, Ipv4Repr};
enum_with_unknown! {
/// Internet protocol control message type.
pub doc enum Message(u8) {
pub enum Message(u8) {
/// Echo reply
EchoReply = 0,
/// Destination unreachable
@ -52,7 +52,7 @@ impl fmt::Display for Message {
enum_with_unknown! {
/// Internet protocol control message subtype for type "Destination Unreachable".
pub doc enum DstUnreachable(u8) {
pub enum DstUnreachable(u8) {
/// Destination network unreachable
NetUnreachable = 0,
/// Destination host unreachable
@ -131,7 +131,7 @@ impl fmt::Display for DstUnreachable {
enum_with_unknown! {
/// Internet protocol control message subtype for type "Redirect Message".
pub doc enum Redirect(u8) {
pub enum Redirect(u8) {
/// Redirect Datagram for the Network
Net = 0,
/// Redirect Datagram for the Host
@ -145,7 +145,7 @@ enum_with_unknown! {
enum_with_unknown! {
/// Internet protocol control message subtype for type "Time Exceeded".
pub doc enum TimeExceeded(u8) {
pub enum TimeExceeded(u8) {
/// TTL expired in transit
TtlExpired = 0,
/// Fragment reassembly time exceeded
@ -155,7 +155,7 @@ enum_with_unknown! {
enum_with_unknown! {
/// Internet protocol control message subtype for type "Parameter Problem".
pub doc enum ParamProblem(u8) {
pub enum ParamProblem(u8) {
/// Pointer indicates the error
AtPointer = 0,
/// Missing a required option

View File

@ -11,7 +11,7 @@ use crate::wire::NdiscRepr;
enum_with_unknown! {
/// Internet protocol control message type.
pub doc enum Message(u8) {
pub enum Message(u8) {
/// Destination Unreachable.
DstUnreachable = 0x01,
/// Packet Too Big.
@ -98,7 +98,7 @@ impl fmt::Display for Message {
enum_with_unknown! {
/// Internet protocol control message subtype for type "Destination Unreachable".
pub doc enum DstUnreachable(u8) {
pub enum DstUnreachable(u8) {
/// No Route to destination.
NoRoute = 0,
/// Communication with destination administratively prohibited.
@ -141,7 +141,7 @@ impl fmt::Display for DstUnreachable {
enum_with_unknown! {
/// Internet protocol control message subtype for the type "Parameter Problem".
pub doc enum ParamProblem(u8) {
pub enum ParamProblem(u8) {
/// Erroneous header field encountered.
ErroneousHdrField = 0,
/// Unrecognized Next Header type encountered.
@ -168,7 +168,7 @@ impl fmt::Display for ParamProblem {
enum_with_unknown! {
/// Internet protocol control message subtype for the type "Time Exceeded".
pub doc enum TimeExceeded(u8) {
pub enum TimeExceeded(u8) {
/// Hop limit exceeded in transit.
HopLimitExceeded = 0,
/// Fragment reassembly time exceeded.

View File

@ -9,7 +9,7 @@ use crate::wire::Ipv4Address;
enum_with_unknown! {
/// Internet Group Management Protocol v1/v2 message version/type.
pub doc enum Message(u8) {
pub enum Message(u8) {
/// Membership Query
MembershipQuery = 0x11,
/// Version 2 Membership Report

View File

@ -3,7 +3,7 @@ use crate::{Error, Result};
enum_with_unknown! {
/// IPv6 Extension Header Option Type
pub doc enum Type(u8) {
pub enum Type(u8) {
/// 1 byte of padding
Pad1 = 0,
/// Multiple bytes of padding
@ -24,7 +24,7 @@ impl fmt::Display for Type {
enum_with_unknown! {
/// Action required when parsing the given IPv6 Extension
/// Header Option Type fails
pub doc enum FailureType(u8) {
pub enum FailureType(u8) {
/// Skip this option and continue processing the packet
Skip = 0b00000000,
/// Discard the containing packet

View File

@ -6,7 +6,7 @@ use crate::wire::Ipv6Address as Address;
enum_with_unknown! {
/// IPv6 Extension Routing Header Routing Type
pub doc enum Type(u8) {
pub enum Type(u8) {
/// Source Route (DEPRECATED)
///
/// See https://tools.ietf.org/html/rfc5095 for details.

View File

@ -15,7 +15,7 @@ enum_with_unknown! {
/// more details.
///
/// [RFC 3810 § 5.2.12]: https://tools.ietf.org/html/rfc3010#section-5.2.12
pub doc enum RecordType(u8) {
pub enum RecordType(u8) {
/// Interface has a filter mode of INCLUDE for the specified multicast address.
ModeIsInclude = 0x01,
/// Interface has a filter mode of EXCLUDE for the specified multicast address.

View File

@ -8,7 +8,7 @@ use crate::wire::{EthernetAddress, Ipv6Address, Ipv6Packet, Ipv6Repr};
enum_with_unknown! {
/// NDISC Option Type
pub doc enum Type(u8) {
pub enum Type(u8) {
/// Source Link-layer Address
SourceLinkLayerAddr = 0x1,
/// Target Link-layer Address