Struct bpf_script::TypeDatabase
source · pub struct TypeDatabase { /* private fields */ }
Expand description
Holds type information.
Implementations
sourceimpl TypeDatabase
impl TypeDatabase
sourcepub fn add_btf_types(&mut self, btf: &Btf) -> Result<()>
pub fn add_btf_types(&mut self, btf: &Btf) -> Result<()>
Adds a parsed list of BTF types to this type database.
Arguments
name
- The optional name of the type.btf
- The BTF types.
Example
use bpf_script::TypeDatabase;
use btf::Btf;
let btf = Btf::from_file("/sys/kernel/btf/vmlinux").expect("Failed to parse vmlinux btf");
let mut database = TypeDatabase::default();
database
.add_btf_types(&btf)
.expect("failed to add btf types");
database
.get_type_by_name("task_struct")
.expect("Couldn't find task_struct");
sourceimpl TypeDatabase
impl TypeDatabase
sourcepub fn get_type_by_name(&self, name: &str) -> Option<&Type>
pub fn get_type_by_name(&self, name: &str) -> Option<&Type>
sourcepub fn get_type_by_id(&self, id: usize) -> Option<&Type>
pub fn get_type_by_id(&self, id: usize) -> Option<&Type>
sourcepub fn get_type_id_by_name(&self, name: &str) -> Option<usize>
pub fn get_type_id_by_name(&self, name: &str) -> Option<usize>
sourcepub fn add_integer(
&mut self,
name: Option<&str>,
bytes: u32,
is_signed: bool
) -> Result<usize>
pub fn add_integer(
&mut self,
name: Option<&str>,
bytes: u32,
is_signed: bool
) -> Result<usize>
Convenience function for adding an integer type to the database.
Arguments
name
- The name of the type.bytes
- The number of bitsis_signed
- If the integer is signed.
sourcepub fn add_float(&mut self, name: Option<&str>, bits: u32) -> Result<usize>
pub fn add_float(&mut self, name: Option<&str>, bits: u32) -> Result<usize>
Convenience function for adding a float type to the database.
Arguments
name
- The name of the type.bits
- The number of bits.
sourcepub fn add_array(
&mut self,
name: Option<&str>,
element_type_id: usize,
num_elements: u32
) -> Result<usize>
pub fn add_array(
&mut self,
name: Option<&str>,
element_type_id: usize,
num_elements: u32
) -> Result<usize>
Convenience function for adding an array to the database.
Arguments
name
- The name of the type.element_type_id
- The type id of the element.num_elements
- The number of elements in the array.
sourcepub fn add_struct(
&mut self,
name: Option<&str>,
fields: &[(&str, Field)]
) -> Result<usize>
pub fn add_struct(
&mut self,
name: Option<&str>,
fields: &[(&str, Field)]
) -> Result<usize>
Convenience function for adding a struct to the database.
Arguments
name
- The name of the type.fields
- The fields to add.
sourcepub fn add_struct_by_names(
&mut self,
name: Option<&str>,
fields: &[(&str, &str)]
) -> Result<usize>
pub fn add_struct_by_names(
&mut self,
name: Option<&str>,
fields: &[(&str, &str)]
) -> Result<usize>
Convenience function for adding a struct to the database using a slice of (field_name, type_name). Types are added in order, and packed together contiguously.
Arguments
name
- The name of the type.fields
- The fields to add (by name).
Trait Implementations
sourceimpl Clone for TypeDatabase
impl Clone for TypeDatabase
sourcefn clone(&self) -> TypeDatabase
fn clone(&self) -> TypeDatabase
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moresourceimpl Debug for TypeDatabase
impl Debug for TypeDatabase
sourceimpl Default for TypeDatabase
impl Default for TypeDatabase
sourcefn default() -> TypeDatabase
fn default() -> TypeDatabase
Returns the “default value” for a type. Read more
Auto Trait Implementations
impl RefUnwindSafe for TypeDatabase
impl Send for TypeDatabase
impl Sync for TypeDatabase
impl Unpin for TypeDatabase
impl UnwindSafe for TypeDatabase
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more