lib.rs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #![feature(range_contains)]
  2. #![no_std]
  3. #[cfg(test)]
  4. #[macro_use]
  5. extern crate std;
  6. extern crate byteorder;
  7. macro_rules! enum_with_unknown {
  8. (#[$( $attr:meta ),*]
  9. pub enum $name:ident($ty:ty) { $( $variant:ident = $value:expr ),+ }) => {
  10. #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Copy)]
  11. #[$( $attr ),*]
  12. pub enum $name {
  13. $( $variant ),*,
  14. Unknown($ty)
  15. }
  16. impl ::core::convert::From<$ty> for $name {
  17. fn from(value: $ty) -> Self {
  18. match value {
  19. $( $value => $name::$variant ),*,
  20. other => $name::Unknown(other)
  21. }
  22. }
  23. }
  24. impl ::core::convert::From<$name> for $ty {
  25. fn from(value: $name) -> Self {
  26. match value {
  27. $( $name::$variant => $value ),*,
  28. $name::Unknown(other) => other
  29. }
  30. }
  31. }
  32. }
  33. }
  34. mod field {
  35. pub type Field = ::core::ops::Range<usize>;
  36. pub type FieldFrom = ::core::ops::RangeFrom<usize>;
  37. }
  38. mod ethernet;
  39. mod arp;
  40. mod ipv4;
  41. pub use ethernet::ProtocolType as EthernetProtocolType;
  42. pub use ethernet::Address as EthernetAddress;
  43. pub use ethernet::Frame as EthernetFrame;
  44. pub use arp::HardwareType as ArpHardwareType;
  45. pub use arp::ProtocolType as ArpProtocolType;
  46. pub use arp::Operation as ArpOperation;
  47. pub use arp::Packet as ArpPacket;
  48. pub use arp::Repr as ArpRepr;
  49. pub use ipv4::Address as Ipv4Address;