@ -48,35 +48,28 @@ impl<K, V> HashMap<K, V> {
}
}
}
}
/// Retrieve the value associate with `key` from the map.
#[ doc = " Retrieves the value associated with `key` from the map. " ]
///
#[ doc = include_str!( " map_safety.md " ) ]
/// # Safety
///
/// Unless the map flag `BPF_F_NO_PREALLOC` is used, the kernel does not guarantee the atomicity
/// of `insert` or `remove`, and any element removed from the map might get aliased by another
/// element in the map, causing garbage to be read, or corruption in case of writes.
#[ inline ]
#[ inline ]
pub unsafe fn get ( & self , key : impl Borrow < K > ) -> Option < & V > {
pub unsafe fn get ( & self , key : impl Borrow < K > ) -> Option < & V > {
unsafe { get ( self . def . get ( ) , key . borrow ( ) ) }
unsafe { get ( self . def . get ( ) , key . borrow ( ) ) }
}
}
/// Retrieve the value associate with `key` from the map.
#[ doc = " Retrieves the pointer associated with `key` from the map. " ]
/// The same caveat as `get` applies, but this returns a raw pointer and it's up to the caller
#[ doc = include_str!( " map_safety.md " ) ]
/// to decide whether it's safe to dereference the pointer or not.
#[ inline ]
#[ inline ]
pub fn get_ptr ( & self , key : impl Borrow < K > ) -> Option < * const V > {
pub fn get_ptr ( & self , key : impl Borrow < K > ) -> Option < * const V > {
get_ptr ( self . def . get ( ) , key . borrow ( ) )
get_ptr ( self . def . get ( ) , key . borrow ( ) )
}
}
/// Retrieve the value associate with `key` from the map.
#[ doc = " Retrieves the mutable pointer associated with `key` from the map. " ]
/// The same caveat as `get` applies, and additionally cares should be taken to avoid
#[ doc = include_str!( " map_safety.md " ) ]
/// concurrent writes, but it's up to the caller to decide whether it's safe to dereference the
/// pointer or not.
#[ inline ]
#[ inline ]
pub fn get_ptr_mut ( & self , key : impl Borrow < K > ) -> Option < * mut V > {
pub fn get_ptr_mut ( & self , key : impl Borrow < K > ) -> Option < * mut V > {
get_ptr_mut ( self . def . get ( ) , key . borrow ( ) )
get_ptr_mut ( self . def . get ( ) , key . borrow ( ) )
}
}
/// Inserts a key-value pair into the map.
#[ inline ]
#[ inline ]
pub fn insert (
pub fn insert (
& self ,
& self ,
@ -87,6 +80,7 @@ impl<K, V> HashMap<K, V> {
insert ( self . def . get ( ) . cast ( ) , key . borrow ( ) , value . borrow ( ) , flags )
insert ( self . def . get ( ) . cast ( ) , key . borrow ( ) , value . borrow ( ) , flags )
}
}
/// Removes a key from the map.
#[ inline ]
#[ inline ]
pub fn remove ( & self , key : impl Borrow < K > ) -> Result < ( ) , c_long > {
pub fn remove ( & self , key : impl Borrow < K > ) -> Result < ( ) , c_long > {
remove ( self . def . get ( ) . cast ( ) , key . borrow ( ) )
remove ( self . def . get ( ) . cast ( ) , key . borrow ( ) )
@ -129,35 +123,28 @@ impl<K, V> LruHashMap<K, V> {
}
}
}
}
/// Retrieve the value associate with `key` from the map.
#[ doc = " Retrieves the value associated with `key` from the map. " ]
///
#[ doc = include_str!( " map_safety.md " ) ]
/// # Safety
///
/// Unless the map flag `BPF_F_NO_PREALLOC` is used, the kernel does not guarantee the atomicity
/// of `insert` or `remove`, and any element removed from the map might get aliased by another
/// element in the map, causing garbage to be read, or corruption in case of writes.
#[ inline ]
#[ inline ]
pub unsafe fn get ( & self , key : impl Borrow < K > ) -> Option < & V > {
pub unsafe fn get ( & self , key : impl Borrow < K > ) -> Option < & V > {
unsafe { get ( self . def . get ( ) , key . borrow ( ) ) }
unsafe { get ( self . def . get ( ) , key . borrow ( ) ) }
}
}
/// Retrieve the value associate with `key` from the map.
#[ doc = " Retrieves the pointer associated with `key` from the map. " ]
/// The same caveat as `get` applies, but this returns a raw pointer and it's up to the caller
#[ doc = include_str!( " map_safety.md " ) ]
/// to decide whether it's safe to dereference the pointer or not.
#[ inline ]
#[ inline ]
pub fn get_ptr ( & self , key : impl Borrow < K > ) -> Option < * const V > {
pub fn get_ptr ( & self , key : impl Borrow < K > ) -> Option < * const V > {
get_ptr ( self . def . get ( ) , key . borrow ( ) )
get_ptr ( self . def . get ( ) , key . borrow ( ) )
}
}
/// Retrieve the value associate with `key` from the map.
#[ doc = " Retrieves the mutable pointer associated with `key` from the map. " ]
/// The same caveat as `get` applies, and additionally cares should be taken to avoid
#[ doc = include_str!( " map_safety.md " ) ]
/// concurrent writes, but it's up to the caller to decide whether it's safe to dereference the
/// pointer or not.
#[ inline ]
#[ inline ]
pub fn get_ptr_mut ( & self , key : impl Borrow < K > ) -> Option < * mut V > {
pub fn get_ptr_mut ( & self , key : impl Borrow < K > ) -> Option < * mut V > {
get_ptr_mut ( self . def . get ( ) , key . borrow ( ) )
get_ptr_mut ( self . def . get ( ) , key . borrow ( ) )
}
}
/// Inserts a key-value pair into the map.
#[ inline ]
#[ inline ]
pub fn insert (
pub fn insert (
& self ,
& self ,
@ -168,6 +155,7 @@ impl<K, V> LruHashMap<K, V> {
insert ( self . def . get ( ) . cast ( ) , key . borrow ( ) , value . borrow ( ) , flags )
insert ( self . def . get ( ) . cast ( ) , key . borrow ( ) , value . borrow ( ) , flags )
}
}
/// Removes a key from the map.
#[ inline ]
#[ inline ]
pub fn remove ( & self , key : impl Borrow < K > ) -> Result < ( ) , c_long > {
pub fn remove ( & self , key : impl Borrow < K > ) -> Result < ( ) , c_long > {
remove ( self . def . get ( ) . cast ( ) , key . borrow ( ) )
remove ( self . def . get ( ) . cast ( ) , key . borrow ( ) )
@ -210,35 +198,28 @@ impl<K, V> PerCpuHashMap<K, V> {
}
}
}
}
/// Retrieve the value associate with `key` from the map.
#[ doc = " Retrieves the value associated with `key` from the map. " ]
///
#[ doc = include_str!( " map_safety.md " ) ]
/// # Safety
///
/// Unless the map flag `BPF_F_NO_PREALLOC` is used, the kernel does not guarantee the atomicity
/// of `insert` or `remove`, and any element removed from the map might get aliased by another
/// element in the map, causing garbage to be read, or corruption in case of writes.
#[ inline ]
#[ inline ]
pub unsafe fn get ( & self , key : impl Borrow < K > ) -> Option < & V > {
pub unsafe fn get ( & self , key : impl Borrow < K > ) -> Option < & V > {
unsafe { get ( self . def . get ( ) , key . borrow ( ) ) }
unsafe { get ( self . def . get ( ) , key . borrow ( ) ) }
}
}
/// Retrieve the value associate with `key` from the map.
#[ doc = " Retrieves the pointer associated with `key` from the map. " ]
/// The same caveat as `get` applies, but this returns a raw pointer and it's up to the caller
#[ doc = include_str!( " map_safety.md " ) ]
/// to decide whether it's safe to dereference the pointer or not.
#[ inline ]
#[ inline ]
pub fn get_ptr ( & self , key : impl Borrow < K > ) -> Option < * const V > {
pub fn get_ptr ( & self , key : impl Borrow < K > ) -> Option < * const V > {
get_ptr ( self . def . get ( ) , key . borrow ( ) )
get_ptr ( self . def . get ( ) , key . borrow ( ) )
}
}
/// Retrieve the value associate with `key` from the map.
#[ doc = " Retrieves the mutable pointer associated with `key` from the map. " ]
/// The same caveat as `get` applies, and additionally cares should be taken to avoid
#[ doc = include_str!( " map_safety.md " ) ]
/// concurrent writes, but it's up to the caller to decide whether it's safe to dereference the
/// pointer or not.
#[ inline ]
#[ inline ]
pub fn get_ptr_mut ( & self , key : impl Borrow < K > ) -> Option < * mut V > {
pub fn get_ptr_mut ( & self , key : impl Borrow < K > ) -> Option < * mut V > {
get_ptr_mut ( self . def . get ( ) , key . borrow ( ) )
get_ptr_mut ( self . def . get ( ) , key . borrow ( ) )
}
}
/// Inserts a key-value pair into the map.
#[ inline ]
#[ inline ]
pub fn insert (
pub fn insert (
& self ,
& self ,
@ -249,6 +230,7 @@ impl<K, V> PerCpuHashMap<K, V> {
insert ( self . def . get ( ) . cast ( ) , key . borrow ( ) , value . borrow ( ) , flags )
insert ( self . def . get ( ) . cast ( ) , key . borrow ( ) , value . borrow ( ) , flags )
}
}
/// Removes a key from the map.
#[ inline ]
#[ inline ]
pub fn remove ( & self , key : impl Borrow < K > ) -> Result < ( ) , c_long > {
pub fn remove ( & self , key : impl Borrow < K > ) -> Result < ( ) , c_long > {
remove ( self . def . get ( ) . cast ( ) , key . borrow ( ) )
remove ( self . def . get ( ) . cast ( ) , key . borrow ( ) )
@ -291,35 +273,28 @@ impl<K, V> LruPerCpuHashMap<K, V> {
}
}
}
}
/// Retrieve the value associate with `key` from the map.
#[ doc = " Retrieves the value associated with `key` from the map. " ]
///
#[ doc = include_str!( " map_safety.md " ) ]
/// # Safety
///
/// Unless the map flag `BPF_F_NO_PREALLOC` is used, the kernel does not guarantee the atomicity
/// of `insert` or `remove`, and any element removed from the map might get aliased by another
/// element in the map, causing garbage to be read, or corruption in case of writes.
#[ inline ]
#[ inline ]
pub unsafe fn get ( & self , key : impl Borrow < K > ) -> Option < & V > {
pub unsafe fn get ( & self , key : impl Borrow < K > ) -> Option < & V > {
unsafe { get ( self . def . get ( ) , key . borrow ( ) ) }
unsafe { get ( self . def . get ( ) , key . borrow ( ) ) }
}
}
/// Retrieve the value associate with `key` from the map.
#[ doc = " Retrieves the pointer associated with `key` from the map. " ]
/// The same caveat as `get` applies, but this returns a raw pointer and it's up to the caller
#[ doc = include_str!( " map_safety.md " ) ]
/// to decide whether it's safe to dereference the pointer or not.
#[ inline ]
#[ inline ]
pub fn get_ptr ( & self , key : impl Borrow < K > ) -> Option < * const V > {
pub fn get_ptr ( & self , key : impl Borrow < K > ) -> Option < * const V > {
get_ptr ( self . def . get ( ) , key . borrow ( ) )
get_ptr ( self . def . get ( ) , key . borrow ( ) )
}
}
/// Retrieve the value associate with `key` from the map.
#[ doc = " Retrieves the mutable pointer associated with `key` from the map. " ]
/// The same caveat as `get` applies, and additionally cares should be taken to avoid
#[ doc = include_str!( " map_safety.md " ) ]
/// concurrent writes, but it's up to the caller to decide whether it's safe to dereference the
/// pointer or not.
#[ inline ]
#[ inline ]
pub fn get_ptr_mut ( & self , key : impl Borrow < K > ) -> Option < * mut V > {
pub fn get_ptr_mut ( & self , key : impl Borrow < K > ) -> Option < * mut V > {
get_ptr_mut ( self . def . get ( ) , key . borrow ( ) )
get_ptr_mut ( self . def . get ( ) , key . borrow ( ) )
}
}
/// Inserts a key-value pair into the map.
#[ inline ]
#[ inline ]
pub fn insert (
pub fn insert (
& self ,
& self ,
@ -330,6 +305,7 @@ impl<K, V> LruPerCpuHashMap<K, V> {
insert ( self . def . get ( ) . cast ( ) , key . borrow ( ) , value . borrow ( ) , flags )
insert ( self . def . get ( ) . cast ( ) , key . borrow ( ) , value . borrow ( ) , flags )
}
}
/// Removes a key from the map.
#[ inline ]
#[ inline ]
pub fn remove ( & self , key : impl Borrow < K > ) -> Result < ( ) , c_long > {
pub fn remove ( & self , key : impl Borrow < K > ) -> Result < ( ) , c_long > {
remove ( self . def . get ( ) . cast ( ) , key . borrow ( ) )
remove ( self . def . get ( ) . cast ( ) , key . borrow ( ) )