Struct libbpf_rs::Object

source ·
pub struct Object { /* private fields */ }
Expand description

Represents a loaded BPF object file.

An Object is logically in charge of all the contained Programs and Maps as well as the associated metadata and runtime state that underpins the userspace portions of BPF program execution. As a libbpf-rs user, you must keep the Object alive during the entire lifetime of your interaction with anything inside the Object.

Note that this is an explanation of the motivation – Rust’s lifetime system should already be enforcing this invariant.

Implementations§

source§

impl Object

source

pub unsafe fn from_ptr(ptr: NonNull<bpf_object>) -> Result<Self>

Takes ownership from pointer.

§Safety

If ptr is not already loaded then further operations on the returned object are undefined.

It is not safe to manipulate ptr after this operation.

source

pub fn btf(&self) -> Result<Option<Btf<'_>>>

Parse the btf information associated with this bpf object.

source

pub fn map<T: AsRef<str>>(&self, name: T) -> Option<&Map>

Get a reference to Map with the name name, if one exists.

source

pub fn map_mut<T: AsRef<str>>(&mut self, name: T) -> Option<&mut Map>

Get a mutable reference to Map with the name name, if one exists.

source

pub fn maps_iter(&self) -> impl Iterator<Item = &Map>

Get an iterator over references to all Maps. Note that this will include automatically generated .data, .rodata, .bss, and .kconfig maps. You may wish to filter this.

source

pub fn maps_iter_mut(&mut self) -> impl Iterator<Item = &mut Map>

Get an iterator over mutable references to all Maps. Note that this will include automatically generated .data, .rodata, .bss, and .kconfig maps. You may wish to filter this.

source

pub fn prog<T: AsRef<str>>(&self, name: T) -> Option<&Program>

Get a reference to Program with the name name, if one exists.

source

pub fn prog_mut<T: AsRef<str>>(&mut self, name: T) -> Option<&mut Program>

Get a mutable reference to Program with the name name, if one exists.

source

pub fn progs_iter(&self) -> impl Iterator<Item = &Program>

Get an iterator over references to all Programs.

source

pub fn progs_iter_mut(&mut self) -> impl Iterator<Item = &mut Program>

Get an iterator over mutable references to all Programs.

Trait Implementations§

source§

impl AsRawLibbpf for Object

source§

fn as_libbpf_object(&self) -> NonNull<Self::LibbpfType>

Retrieve the underlying libbpf_sys::bpf_object.

§

type LibbpfType = bpf_object

The underlying libbpf type.
source§

impl Debug for Object

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Drop for Object

source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl Freeze for Object

§

impl RefUnwindSafe for Object

§

impl !Send for Object

§

impl !Sync for Object

§

impl Unpin for Object

§

impl UnwindSafe for Object

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.