libbpf_rs::btf

Struct Btf

Source
pub struct Btf<'source> { /* private fields */ }
Expand description

The btf information of a bpf object.

The lifetime bound protects against this object outliving its source. This can happen when it was derived from an Object, which owns the data this structs points too. When instead the Btf::from_path method is used, the lifetime will be 'static since it doesn’t borrow from anything.

Implementations§

Source§

impl Btf<'static>

Source

pub fn from_path<P: AsRef<Path>>(path: P) -> Result<Self>

Load the btf information from specified path.

Source

pub fn from_vmlinux() -> Result<Self>

Load the vmlinux btf information from few well-known locations.

Source

pub fn from_prog_id(id: u32) -> Result<Self>

Load the btf information of an bpf object from a program id.

Source§

impl<'btf> Btf<'btf>

Source

pub fn from_bpf_object(obj: &'btf bpf_object) -> Result<Option<Self>>

Create a new Btf instance from the given libbpf_sys::bpf_object.

Source

pub fn from_raw( name: &'btf str, object_file: &'btf [u8], ) -> Result<Option<Self>>

From raw bytes coming from an object file.

Source

pub fn is_empty(&self) -> bool

Whether this btf instance has no types.

Source

pub fn len(&self) -> usize

The number of BtfTypes in this object.

Source

pub fn ptr_size(&self) -> Result<NonZeroUsize>

The btf pointer size.

Source

pub fn type_by_name<'s, K>(&'s self, name: &str) -> Option<K>
where K: TryFrom<BtfType<'s>>,

Find a btf type by name

§Panics

If name has null bytes.

Source

pub fn type_by_id<'s, K>(&'s self, type_id: TypeId) -> Option<K>
where K: TryFrom<BtfType<'s>>,

Find a type by it’s TypeId.

Source

pub fn type_by_kind<'s, K>(&'s self) -> impl Iterator<Item = K> + 's
where K: TryFrom<BtfType<'s>>,

Find all types of a specific type kind.

Trait Implementations§

Source§

impl AsRawLibbpf for Btf<'_>

Source§

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

Retrieve the underlying libbpf_sys::btf object.

Source§

type LibbpfType = btf

The underlying libbpf type.
Source§

impl Debug for Btf<'_>

Source§

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

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

impl Drop for Btf<'_>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<'source> Freeze for Btf<'source>

§

impl<'source> RefUnwindSafe for Btf<'source>

§

impl<'source> !Send for Btf<'source>

§

impl<'source> !Sync for Btf<'source>

§

impl<'source> Unpin for Btf<'source>

§

impl<'source> UnwindSafe for Btf<'source>

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>,

Source§

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>,

Source§

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.