Skip to main content

push_packet/
loader.rs

1use aya::{Ebpf, EbpfLoader};
2
3use crate::Error;
4
5/// This trait enforces organizational principles for configuring and loading Ebpf components. This
6/// should be implemented on configuration structs, in a builder pattern, using `load(self, ebpf:
7/// &mut Ebpf)` instead of the common `build(self)`.
8pub trait Loader {
9    /// The component that is loaded.
10    type Component;
11
12    /// Optionally set map max entries or otherwise interact with the [`EbpfLoader`].
13    ///
14    /// # Errors
15    /// Returns an [`Error`] if the configuration fails.
16    fn configure(&self, _ebpf_loader: &mut EbpfLoader) -> Result<(), Error> {
17        Ok(())
18    }
19    /// Loads the [`Self::Component`]
20    ///
21    /// # Errors
22    /// Returns as [`Error`] if the [`Self::Component`] can not be loaded.
23    fn load(self, ebpf: &mut Ebpf) -> Result<Self::Component, Error>;
24}