From e4c0cb1f5af3788a19ae2792de6f1e42d4e017e7 Mon Sep 17 00:00:00 2001 From: Dave Tucker Date: Sun, 29 May 2022 15:00:31 +0100 Subject: [PATCH] aya: Add MapFd trait This allows for programs to get a maps fd, like the program fd trait. Signed-off-by: Dave Tucker --- aya/src/maps/mod.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/aya/src/maps/mod.rs b/aya/src/maps/mod.rs index dcbca570..e25e6f44 100644 --- a/aya/src/maps/mod.rs +++ b/aya/src/maps/mod.rs @@ -306,6 +306,18 @@ impl Drop for Map { } } +/// Allows the Fd of a loaded [`Map`] to be retrieved +pub trait MapFd { + /// Returns the [`RawFd`] of the program if it has been loaded, or `None` + fn fd(&self) -> Option; +} + +impl MapFd for Map { + fn fd(&self) -> Option { + self.fd + } +} + /// An iterable map pub trait IterableMap { /// Get a generic map handle