Browse Source

Doc fixes

Alessandro Decina 3 years ago
parent
commit
be0b7bbd83

+ 1 - 1
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()?;

+ 1 - 3
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))

+ 13 - 13
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<T: Deref<Target = Map>, V: Pod> {
     inner: T,
@@ -80,19 +93,6 @@ impl<T: Deref<Target = Map> + DerefMut<Target = Map>, V: Pod> Queue<T, V> {
     /// # 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)| {

+ 1 - 2
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;

+ 1 - 1
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()?;