Skip to content

Commit

Permalink
remove wildcard from match (#61)
Browse files Browse the repository at this point in the history
  • Loading branch information
leshow committed Sep 18, 2023
1 parent 751c4f1 commit 9595376
Show file tree
Hide file tree
Showing 10 changed files with 411 additions and 399 deletions.
6 changes: 3 additions & 3 deletions dhcproto-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ fn generate_dhcpoption_code<'a>(entries: &'a [Entry]) -> impl Iterator<Item = St
"
impl From<&DhcpOption> for OptionCode {
fn from(opt: &DhcpOption) -> Self {
use DhcpOption::*;
use DhcpOption as O;
match opt {
"
.to_owned(),
Expand All @@ -164,10 +164,10 @@ fn generate_dhcpoption_code<'a>(entries: &'a [Entry]) -> impl Iterator<Item = St
} else {
"".to_owned()
};
format!("{id}{var_field} => OptionCode::{id},")
format!("O::{id}{var_field} => OptionCode::{id},")
}))
.chain(std::iter::once(
"Unknown(n) => OptionCode::Unknown(n.code)}}}".to_owned(),
"O::Unknown(n) => OptionCode::Unknown(n.code)}}}".to_owned(),
));

impl_dhcp_option.chain(impl_optioncode_from_dhcpoption_ref)
Expand Down
5 changes: 3 additions & 2 deletions src/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,18 @@ use crate::error::{EncodeError, EncodeResult};

/// A trait for types which are deserializable to DHCP binary formats
pub trait Encodable {
/// Read the type from the stream
/// encode type to buffer in Encoder
fn encode(&self, e: &mut Encoder<'_>) -> EncodeResult<()>;

/// encode this type into a new `Vec`
/// encode this type into its binary form in a new `Vec`
fn to_vec(&self) -> EncodeResult<Vec<u8>> {
let mut buffer = Vec::with_capacity(512);
let mut encoder = Encoder::new(&mut buffer);
self.encode(&mut encoder)?;
Ok(buffer)
}
}

/// Encoder type, holds a mut ref to a buffer
/// that it will write data to and an offset
/// of the next position to write
Expand Down
34 changes: 17 additions & 17 deletions src/v4/bulk_query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,17 +82,17 @@ impl From<u8> for QueryState {

impl From<QueryState> for u8 {
fn from(state: QueryState) -> Self {
use QueryState::*;
use QueryState as Q;
match state {
Available => 1,
Active => 2,
Expired => 3,
Release => 4,
Abandoned => 5,
Reset => 6,
Remote => 7,
Transitioning => 8,
Unknown(code) => code,
Q::Available => 1,
Q::Active => 2,
Q::Expired => 3,
Q::Release => 4,
Q::Abandoned => 5,
Q::Reset => 6,
Q::Remote => 7,
Q::Transitioning => 8,
Q::Unknown(code) => code,
}
}
}
Expand Down Expand Up @@ -124,14 +124,14 @@ impl From<u8> for Code {

impl From<Code> for u8 {
fn from(code: Code) -> Self {
use Code::*;
use Code as C;
match code {
Success => 0,
UnspecFail => 1,
QueryTerminated => 2,
MalformedQuery => 3,
NotAllowed => 4,
Unknown(code) => code,
C::Success => 0,
C::UnspecFail => 1,
C::QueryTerminated => 2,
C::MalformedQuery => 3,
C::NotAllowed => 4,
C::Unknown(code) => code,
}
}
}
Expand Down
58 changes: 29 additions & 29 deletions src/v4/htype.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,36 +107,36 @@ impl From<u8> for HType {

impl From<HType> for u8 {
fn from(n: HType) -> Self {
use HType::*;
use HType as H;
match n {
Eth => 1,
ExperimentalEth => 2,
AmRadioAX25 => 3,
ProteonTokenRing => 4,
Chaos => 5,
IEEE802 => 6,
ARCNET => 7,
Hyperchannel => 8,
Lanstar => 9,
AutonetShortAddr => 10,
LocalTalk => 11,
LocalNet => 12,
Ultralink => 13,
SMDS => 14,
FrameRelay => 15,
HDLC => 17,
FibreChannel => 18,
SerialLine => 20,
MilStd188220 => 22,
Metricom => 23,
MAPOS => 25,
Twinaxial => 26,
ARPSec => 30,
IPsecTunnel => 31,
Infiniband => 32,
WiegandInt => 34,
PureIP => 35,
Unknown(n) => n,
H::Eth => 1,
H::ExperimentalEth => 2,
H::AmRadioAX25 => 3,
H::ProteonTokenRing => 4,
H::Chaos => 5,
H::IEEE802 => 6,
H::ARCNET => 7,
H::Hyperchannel => 8,
H::Lanstar => 9,
H::AutonetShortAddr => 10,
H::LocalTalk => 11,
H::LocalNet => 12,
H::Ultralink => 13,
H::SMDS => 14,
H::FrameRelay => 15,
H::HDLC => 17,
H::FibreChannel => 18,
H::SerialLine => 20,
H::MilStd188220 => 22,
H::Metricom => 23,
H::MAPOS => 25,
H::Twinaxial => 26,
H::ARPSec => 30,
H::IPsecTunnel => 31,
H::Infiniband => 32,
H::WiegandInt => 34,
H::PureIP => 35,
H::Unknown(n) => n,
}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/v4/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ pub use crate::{
};

pub const MAGIC: [u8; 4] = [99, 130, 83, 99];
pub const MIN_PACKET_SIZE: usize = 300;

/// default dhcpv4 server port
pub const SERVER_PORT: u16 = 67;
Expand Down
Loading

0 comments on commit 9595376

Please sign in to comment.