pub struct TypeDatabase { /* private fields */ }
Expand description

Holds type information.

Implementations

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");

Adds a type to the type database.

Arguments
  • name - The name of the type.
  • ty - The type to add.

Finds a type in the database by name.

Arguments
  • name - The name of the type.

Finds a type in the database by id.

Arguments
  • id - The id of the type.

Gets a type’s id by its name.

Arguments
  • name - The name of the type.

Convenience function for adding an integer type to the database.

Arguments
  • name - The name of the type.
  • bytes - The number of bits
  • is_signed - If the integer is signed.

Convenience function for adding a float type to the database.

Arguments
  • name - The name of the type.
  • bits - The number of bits.

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.

Convenience function for adding a struct to the database.

Arguments
  • name - The name of the type.
  • fields - The fields to add.

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

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Returns the “default value” for a type. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

Should always be Self
The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.