feat: Add `set` for `Array<T>`

Signed-off-by: jinlong <jinlong@tencent.com>
reviewable/pr1199/r1
jinlong 8 months ago committed by Tamir Duberstein
parent 601c89dd23
commit 2fb19f3ee2

@ -1,8 +1,10 @@
use core::{cell::UnsafeCell, marker::PhantomData, mem, ptr::NonNull}; use core::{cell::UnsafeCell, marker::PhantomData, mem, ptr::NonNull};
use aya_ebpf_cty::c_long;
use crate::{ use crate::{
bindings::{bpf_map_def, bpf_map_type::BPF_MAP_TYPE_ARRAY}, bindings::{bpf_map_def, bpf_map_type::BPF_MAP_TYPE_ARRAY},
lookup, insert, lookup,
maps::PinningType, maps::PinningType,
}; };
@ -65,4 +67,10 @@ impl<T> Array<T> {
unsafe fn lookup(&self, index: u32) -> Option<NonNull<T>> { unsafe fn lookup(&self, index: u32) -> Option<NonNull<T>> {
lookup(self.def.get(), &index) lookup(self.def.get(), &index)
} }
/// Sets the value of the element at the given index.
#[inline(always)]
pub fn set(&self, index: u32, value: &T, flags: u64) -> Result<(), c_long> {
insert(self.def.get(), &index, value, flags)
}
} }

@ -85,6 +85,7 @@ pub fn aya_ebpf::maps::array::Array<T>::get(&self, index: u32) -> core::option::
pub fn aya_ebpf::maps::array::Array<T>::get_ptr(&self, index: u32) -> core::option::Option<*const T> pub fn aya_ebpf::maps::array::Array<T>::get_ptr(&self, index: u32) -> core::option::Option<*const T>
pub fn aya_ebpf::maps::array::Array<T>::get_ptr_mut(&self, index: u32) -> core::option::Option<*mut T> pub fn aya_ebpf::maps::array::Array<T>::get_ptr_mut(&self, index: u32) -> core::option::Option<*mut T>
pub const fn aya_ebpf::maps::array::Array<T>::pinned(max_entries: u32, flags: u32) -> aya_ebpf::maps::array::Array<T> pub const fn aya_ebpf::maps::array::Array<T>::pinned(max_entries: u32, flags: u32) -> aya_ebpf::maps::array::Array<T>
pub fn aya_ebpf::maps::array::Array<T>::set(&self, index: u32, value: &T, flags: u64) -> core::result::Result<(), aya_ebpf_cty::od::c_long>
pub const fn aya_ebpf::maps::array::Array<T>::with_max_entries(max_entries: u32, flags: u32) -> aya_ebpf::maps::array::Array<T> pub const fn aya_ebpf::maps::array::Array<T>::with_max_entries(max_entries: u32, flags: u32) -> aya_ebpf::maps::array::Array<T>
impl<T: core::marker::Sync> core::marker::Sync for aya_ebpf::maps::array::Array<T> impl<T: core::marker::Sync> core::marker::Sync for aya_ebpf::maps::array::Array<T>
impl<T> !core::marker::Freeze for aya_ebpf::maps::array::Array<T> impl<T> !core::marker::Freeze for aya_ebpf::maps::array::Array<T>
@ -763,6 +764,7 @@ pub fn aya_ebpf::maps::array::Array<T>::get(&self, index: u32) -> core::option::
pub fn aya_ebpf::maps::array::Array<T>::get_ptr(&self, index: u32) -> core::option::Option<*const T> pub fn aya_ebpf::maps::array::Array<T>::get_ptr(&self, index: u32) -> core::option::Option<*const T>
pub fn aya_ebpf::maps::array::Array<T>::get_ptr_mut(&self, index: u32) -> core::option::Option<*mut T> pub fn aya_ebpf::maps::array::Array<T>::get_ptr_mut(&self, index: u32) -> core::option::Option<*mut T>
pub const fn aya_ebpf::maps::array::Array<T>::pinned(max_entries: u32, flags: u32) -> aya_ebpf::maps::array::Array<T> pub const fn aya_ebpf::maps::array::Array<T>::pinned(max_entries: u32, flags: u32) -> aya_ebpf::maps::array::Array<T>
pub fn aya_ebpf::maps::array::Array<T>::set(&self, index: u32, value: &T, flags: u64) -> core::result::Result<(), aya_ebpf_cty::od::c_long>
pub const fn aya_ebpf::maps::array::Array<T>::with_max_entries(max_entries: u32, flags: u32) -> aya_ebpf::maps::array::Array<T> pub const fn aya_ebpf::maps::array::Array<T>::with_max_entries(max_entries: u32, flags: u32) -> aya_ebpf::maps::array::Array<T>
impl<T: core::marker::Sync> core::marker::Sync for aya_ebpf::maps::array::Array<T> impl<T: core::marker::Sync> core::marker::Sync for aya_ebpf::maps::array::Array<T>
impl<T> !core::marker::Freeze for aya_ebpf::maps::array::Array<T> impl<T> !core::marker::Freeze for aya_ebpf::maps::array::Array<T>

Loading…
Cancel
Save