瀏覽代碼

Merge pull request #121 from eero-thia/thia/programs_mut

aya: programs_mut iterator to complement programs.
Alessandro Decina 3 年之前
父節點
當前提交
2955ca1d1f
共有 1 個文件被更改,包括 17 次插入1 次删除
  1. 17 1
      aya/src/bpf.rs

+ 17 - 1
aya/src/bpf.rs

@@ -521,7 +521,7 @@ impl Bpf {
     ///
     /// # Examples
     /// ```no_run
-    /// # let mut bpf = aya::Bpf::load(&[])?;
+    /// # let bpf = aya::Bpf::load(&[])?;
     /// for program in bpf.programs() {
     ///     println!(
     ///         "found program `{}` of type `{:?}`",
@@ -534,6 +534,22 @@ impl Bpf {
     pub fn programs(&self) -> impl Iterator<Item = &Program> {
         self.programs.values()
     }
+
+    /// An iterator mutably referencing all of the programs.
+    ///
+    /// # Examples
+    /// ```no_run
+    /// # use std::path::Path;
+    /// # let mut bpf = aya::Bpf::load(&[])?;
+    /// # let pin_path = Path::new("/tmp/pin_path");
+    /// for program in bpf.programs_mut() {
+    ///     program.pin(pin_path)?;
+    /// }
+    /// # Ok::<(), aya::BpfError>(())
+    /// ```
+    pub fn programs_mut(&mut self) -> impl Iterator<Item = &mut Program> {
+        self.programs.values_mut()
+    }
 }
 
 /// The error type returned by [`Bpf::load_file`] and [`Bpf::load`].