From 2c02c2520dd42d1132fcd13ea78c160f96171d01 Mon Sep 17 00:00:00 2001 From: Nikolay Edigaryev Date: Wed, 8 Jun 2022 03:32:30 +0300 Subject: [PATCH] README.md: remove main() and de-indent the usage example --- README.md | 44 +++++++++++++++++++++----------------------- 1 file changed, 21 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index 13fd22f..18c1d87 100644 --- a/README.md +++ b/README.md @@ -18,32 +18,30 @@ Ensure that your software either has an `com.apple.vm.networking` entitlement or Start a NAT interface and receive some packets destined to it: ```rust -fn main() { - let shared_mode = Shared { - subnet_options: None, - ..Default::default() - }; - - let mut iface = Interface::new(Mode::Shared(shared_mode), Options::default()).unwrap(); - - let (tx, rx) = sync::mpsc::sync_channel(0); - - iface.set_event_callback(Events::PACKETS_AVAILABLE, move |events, params| { - if let Some(Parameter::EstimatedPacketsAvailable(pkts)) = params.get(ParameterKind::EstimatedPacketsAvailable) { - tx.send(pkts); - } - }).unwrap(); - - let pkts = rx.recv().unwrap(); - println!("receiving {} packets...", pkts); - for _ in 0..pkts { - let mut buf: [u8; 1514] = [0; 1514]; - println!("{:?}", iface.read(&mut buf)); +let shared_mode = Shared { + subnet_options: None, + ..Default::default() +}; + +let mut iface = Interface::new(Mode::Shared(shared_mode), Options::default()).unwrap(); + +let (tx, rx) = sync::mpsc::sync_channel(0); + +iface.set_event_callback(Events::PACKETS_AVAILABLE, move |events, params| { + if let Some(Parameter::EstimatedPacketsAvailable(pkts)) = params.get(ParameterKind::EstimatedPacketsAvailable) { + tx.send(pkts); } +}).unwrap(); - drop(rx); - iface.finalize().unwrap(); +let pkts = rx.recv().unwrap(); +println!("receiving {} packets...", pkts); +for _ in 0..pkts { + let mut buf: [u8; 1514] = [0; 1514]; + println!("{:?}", iface.read(&mut buf)); } + +drop(rx); +iface.finalize().unwrap(); ``` ## Quirks and missing functionality