Skip to content

Commit 58dd55c

Browse files
committed
refactor(dht): move unpack macro to binary_io
1 parent 2f9d54b commit 58dd55c

File tree

6 files changed

+17
-51
lines changed

6 files changed

+17
-51
lines changed

src/toxcore/binary_io.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,3 +135,20 @@ macro_rules! encode_decode_test (
135135
}
136136
)
137137
);
138+
139+
/// Extract inner content of enums.
140+
#[cfg(test)]
141+
macro_rules! unpack {
142+
($variable:expr, $variant:path, $name:ident) => (
143+
match $variable {
144+
$variant { $name, .. } => $name,
145+
other => panic!("Expected {} but got {:?}", stringify!($variant), other),
146+
}
147+
);
148+
($variable:expr, $variant:path) => (
149+
match $variable {
150+
$variant(inner) => inner,
151+
other => panic!("Expected {} but got {:?}", stringify!($variant), other),
152+
}
153+
)
154+
}

src/toxcore/dht/lan_discovery.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -145,15 +145,6 @@ mod tests {
145145

146146
use futures::{Future, Stream};
147147

148-
macro_rules! unpack {
149-
($variable:expr, $variant:path) => (
150-
match $variable {
151-
$variant(inner) => inner,
152-
other => panic!("Expected {} but got {:?}", stringify!($variant), other),
153-
}
154-
)
155-
}
156-
157148
fn broadcast_addrs_count() -> usize {
158149
get_if_addrs::get_if_addrs().expect("no network interface").iter().filter_map(|interface|
159150
match interface.addr {

src/toxcore/dht/server/hole_punching.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -260,15 +260,6 @@ mod tests {
260260
use futures::sync::mpsc;
261261
use std::thread;
262262

263-
macro_rules! unpack {
264-
($variable:expr, $variant:path) => (
265-
match $variable {
266-
$variant(inner) => inner,
267-
other => panic!("Expected {} but got {:?}", stringify!($variant), other),
268-
}
269-
)
270-
}
271-
272263
#[test]
273264
fn hole_punch_new_test() {
274265
let hole_punch = HolePunching::new();

src/toxcore/dht/server/mod.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1133,15 +1133,6 @@ mod tests {
11331133
const ONION_RETURN_2_PAYLOAD_SIZE: usize = ONION_RETURN_2_SIZE - secretbox::NONCEBYTES;
11341134
const ONION_RETURN_3_PAYLOAD_SIZE: usize = ONION_RETURN_3_SIZE - secretbox::NONCEBYTES;
11351135

1136-
macro_rules! unpack {
1137-
($variable:expr, $variant:path) => (
1138-
match $variable {
1139-
$variant(inner) => inner,
1140-
other => panic!("Expected {} but got {:?}", stringify!($variant), other),
1141-
}
1142-
)
1143-
}
1144-
11451136
fn create_node() -> (Server, PrecomputedKey, PublicKey, SecretKey,
11461137
mpsc::UnboundedReceiver<(DhtPacket, SocketAddr)>, SocketAddr) {
11471138
crypto_init();

src/toxcore/dht/server/ping_sender.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -129,15 +129,6 @@ mod tests {
129129

130130
const BOOTSTRAP_TIMES: u32 = 5;
131131

132-
macro_rules! unpack {
133-
($variable:expr, $variant:path) => (
134-
match $variable {
135-
$variant(inner) => inner,
136-
other => panic!("Expected {} but got {:?}", stringify!($variant), other),
137-
}
138-
)
139-
}
140-
141132
#[test]
142133
fn ping_new_test() {
143134
let _ = PingSender::new();

src/toxcore/net_crypto/mod.rs

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -660,21 +660,6 @@ mod tests {
660660

661661
use toxcore::time::ConstNow;
662662

663-
macro_rules! unpack {
664-
($variable:expr, $variant:path, $name:ident) => (
665-
match $variable {
666-
$variant { $name, .. } => $name,
667-
other => panic!("Expected {} but got {:?}", stringify!($variant), other),
668-
}
669-
);
670-
($variable:expr, $variant:path) => (
671-
match $variable {
672-
$variant(inner) => inner,
673-
other => panic!("Expected {} but got {:?}", stringify!($variant), other),
674-
}
675-
)
676-
}
677-
678663
#[test]
679664
fn net_crypto_clone() {
680665
let (udp_tx, _udp_rx) = mpsc::unbounded();

0 commit comments

Comments
 (0)