diff --git a/README.md b/README.md index 10cde014..e4ed17b0 100644 --- a/README.md +++ b/README.md @@ -58,7 +58,7 @@ use aya::Bpf; use aya::programs::{CgroupSkb, CgroupSkbAttachType}; // load the BPF code -let bpf = Bpf::load_file("bpf.o")?; +let mut bpf = Bpf::load_file("bpf.o")?; // get the `ingress_filter` program compiled into `bpf.o`. let ingress: &mut CgroupSkb = bpf.program_mut("ingress_filter")?.try_into()?; diff --git a/aya/src/maps/perf/async_perf_event_array.rs b/aya/src/maps/perf/async_perf_event_array.rs index 6876b197..ebf341c3 100644 --- a/aya/src/maps/perf/async_perf_event_array.rs +++ b/aya/src/maps/perf/async_perf_event_array.rs @@ -41,24 +41,22 @@ use crate::maps::{ /// # PerfBuf(#[from] aya::maps::perf::PerfBufferError), /// # } /// # async fn try_main() -> Result<(), Error> { -/// # use async_std::task; /// # let bpf = aya::Bpf::load(&[], None)?; /// use aya::maps::perf::{AsyncPerfEventArray, PerfBufferError}; /// use aya::util::online_cpus; /// use std::convert::TryFrom; /// use futures::future; /// use bytes::BytesMut; +/// use tokio::task; // or async_std::task /// /// // try to convert the PERF_ARRAY map to an AsyncPerfEventArray /// let mut perf_array = AsyncPerfEventArray::try_from(bpf.map_mut("PERF_ARRAY")?)?; /// -/// let mut futs = Vec::new(); /// for cpu_id in online_cpus()? { /// // open a separate perf buffer for each cpu /// let mut buf = perf_array.open(cpu_id, None)?; /// /// // process each perf buffer in a separate task -/// // NOTE: use async_std::task::spawn with async-std and tokio::spawn with tokio /// task::spawn(async move { /// let mut buffers = (0..10) /// .map(|_| BytesMut::with_capacity(1024)) diff --git a/aya/src/maps/queue.rs b/aya/src/maps/queue.rs index 95bb7558..fb841905 100644 --- a/aya/src/maps/queue.rs +++ b/aya/src/maps/queue.rs @@ -14,6 +14,19 @@ use crate::{ }; /// A FIFO queue. +/// +/// # Examples +/// ```no_run +/// # let bpf = aya::Bpf::load(&[], None)?; +/// use aya::maps::Queue; +/// use std::convert::TryFrom; +/// +/// let mut queue = Queue::try_from(bpf.map_mut("ARRAY")?)?; +/// queue.push(42, 0)?; +/// queue.push(43, 0)?; +/// assert_eq!(queue.pop(0)?, 42); +/// # Ok::<(), aya::BpfError>(()) +/// ``` #[doc(alias = "BPF_MAP_TYPE_QUEUE")] pub struct Queue, V: Pod> { inner: T, @@ -80,19 +93,6 @@ impl + DerefMut, V: Pod> Queue { /// # Errors /// /// [`MapError::SyscallError`] if `bpf_map_update_elem` fails. - /// - /// # Examples - /// ```no_run - /// # let bpf = aya::Bpf::load(&[], None)?; - /// use aya::maps::Queue; - /// use std::convert::TryFrom; - /// - /// let mut queue = Queue::try_from(bpf.map_mut("ARRAY")?)?; - /// queue.push(42, 0)?; - /// queue.push(43, 0)?; - /// assert_eq!(queue.pop(0)?, 42); - /// # Ok::<(), aya::BpfError>(()) - /// ``` pub fn push(&mut self, value: V, flags: u64) -> Result<(), MapError> { let fd = self.inner.fd_or_err()?; bpf_map_push_elem(fd, &value, flags).map_err(|(code, io_error)| { diff --git a/aya/src/programs/socket_filter.rs b/aya/src/programs/socket_filter.rs index acd475f8..7fe0d23b 100644 --- a/aya/src/programs/socket_filter.rs +++ b/aya/src/programs/socket_filter.rs @@ -42,8 +42,7 @@ pub enum SocketFilterError { /// # Bpf(#[from] aya::BpfError) /// # } /// # let mut bpf = aya::Bpf::load(&[], None)?; -/// use std::convert::{TryFrom, TryInto}; -/// use std::io::Write; +/// use std::convert::TryInto; /// use std::net::TcpStream; /// use std::os::unix::io::AsRawFd; /// use aya::programs::SocketFilter; diff --git a/aya/src/programs/trace_point.rs b/aya/src/programs/trace_point.rs index 8b27f74a..5e7e2840 100644 --- a/aya/src/programs/trace_point.rs +++ b/aya/src/programs/trace_point.rs @@ -37,7 +37,7 @@ pub enum TracePointError { /// # Bpf(#[from] aya::BpfError) /// # } /// # let mut bpf = aya::Bpf::load(&[], None)?; -/// use std::convert::{TryFrom, TryInto}; +/// use std::convert::TryInto; /// use aya::programs::TracePoint; /// /// let prog: &mut TracePoint = bpf.program_mut("trace_context_switch")?.try_into()?;