Skip to content

Commit 316c46c

Browse files
Julian-WollersbergerJulian
and
Julian
authored
Fix the examples and compile them in doc tests. (#296)
Co-authored-by: Julian <julian.wollersberger@frauscher.com>
1 parent ff3eb23 commit 316c46c

File tree

1 file changed

+19
-21
lines changed

1 file changed

+19
-21
lines changed

src/lib.rs

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,15 @@
88
//! use `.open()` on a `Device`. You can obtain the "default" device using
99
//! `Device::lookup()`, or you can obtain the device(s) you need via `Device::list()`.
1010
//!
11-
//! ```ignore
11+
//! ```no_run
1212
//! use pcap::Device;
1313
//!
14-
//! fn main() {
15-
//! let mut cap = Device::lookup().unwrap().open().unwrap();
14+
//! let mut cap = Device::lookup().unwrap().unwrap().open().unwrap();
1615
//!
17-
//! while let Ok(packet) = cap.next_packet() {
18-
//! println!("received packet! {:?}", packet);
19-
//! }
16+
//! while let Ok(packet) = cap.next_packet() {
17+
//! println!("received packet! {:?}", packet);
2018
//! }
19+
//!
2120
//! ```
2221
//!
2322
//! `Capture`'s `.next_packet()` will produce a `Packet` which can be dereferenced to access the
@@ -30,19 +29,17 @@
3029
//! proceed to configure the capture handle. When you're finished, run `.open()` on it to
3130
//! turn it into a `Capture<Active>`.
3231
//!
33-
//! ```ignore
34-
//! use pcap::{Device,Capture};
32+
//! ```no_run
33+
//! use pcap::{Device, Capture};
3534
//!
36-
//! fn main() {
37-
//! let main_device = Device::lookup().unwrap();
38-
//! let mut cap = Capture::from_device(main_device).unwrap()
39-
//! .promisc(true)
40-
//! .snaplen(5000)
41-
//! .open().unwrap();
35+
//! let main_device = Device::lookup().unwrap().unwrap();
36+
//! let mut cap = Capture::from_device(main_device).unwrap()
37+
//! .promisc(true)
38+
//! .snaplen(5000)
39+
//! .open().unwrap();
4240
//!
43-
//! while let Ok(packet) = cap.next_packet() {
44-
//! println!("received packet! {:?}", packet);
45-
//! }
41+
//! while let Ok(packet) = cap.next_packet() {
42+
//! println!("received packet! {:?}", packet);
4643
//! }
4744
//! ```
4845
//!
@@ -806,8 +803,9 @@ impl State for Dead {}
806803
///
807804
/// # Example:
808805
///
809-
/// ```ignore
810-
/// let cap = Capture::from_device(Device::lookup().unwrap()) // open the "default" interface
806+
/// ```no_run
807+
/// # use pcap::{Capture, Device};
808+
/// let mut cap = Capture::from_device(Device::lookup().unwrap().unwrap()) // open the "default" interface
811809
/// .unwrap() // assume the device exists and we are authorized to open it
812810
/// .open() // activate the handle
813811
/// .unwrap(); // assume activation worked
@@ -1290,7 +1288,7 @@ impl<T: Activated + ?Sized> Capture<T> {
12901288
/// compiled using `pcap_compile()`. `optimize` controls whether optimization on the resulting
12911289
/// code is performed
12921290
///
1293-
/// See http://biot.com/capstats/bpf.html for more information about this syntax.
1291+
/// See <http://biot.com/capstats/bpf.html> for more information about this syntax.
12941292
pub fn filter(&mut self, program: &str, optimize: bool) -> Result<(), Error> {
12951293
let program = CString::new(program)?;
12961294
unsafe {
@@ -1312,7 +1310,7 @@ impl<T: Activated + ?Sized> Capture<T> {
13121310
/// Get capture statistics about this capture. The values represent packet statistics from the
13131311
/// start of the run to the time of the call.
13141312
///
1315-
/// See https://www.tcpdump.org/manpages/pcap_stats.3pcap.html for per-platform caveats about
1313+
/// See <https://www.tcpdump.org/manpages/pcap_stats.3pcap.html> for per-platform caveats about
13161314
/// how packet statistics are calculated.
13171315
pub fn stats(&mut self) -> Result<Stat, Error> {
13181316
unsafe {

0 commit comments

Comments
 (0)