Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
libbpf-rs
aims to be a convenient but thin wrapper aroundlibbpf
functionality. Not all functionality provided oflibbpf
is exposed through its API. This can quickly become a blocker if, say, some getter is not hooked up, but the value required to perform an operation. In the spirit of being a thin wrapper, it makes sense for us to provide access to the underlyinglibbpf
objects. When nothing else is available, these can be used directly in conjunction withlibbpf-sys
to, effectively, write Rust-syntax C code.So far we have provided very ad-hoc accessor methods for retrieving pointers to the underlying
libbpf
objects. With this change we formalize this approach some more, by introducing theAsLibbpfObject
trait and implementing it for majorlibbpf-rs
types.Using a trait is not the only possible way. We could also continue that path we were on earlier where relevant types had custom named accessors without a common trait (e.g.,
Map::as_libbpf_bpf_map_ptr
). The benefits a trait brings to the table is that it unifies naming and makes it reasonably easy to get an overview of types that havelibbpf
counterparts.The risk is that we may have to adjust the trait signature in one way or another if a newly added type has different constraints (e.g., if a
libbpf-rs
object has a potentially-NULL
libbpf object).