@ -148,38 +148,30 @@ impl Bpf {
} )
} )
}
}
pub fn map < T : TryFrom < MapRef > > (
pub fn map ( & self , name : & str ) -> Result < MapRef , MapError > {
& self ,
name : & str ,
) -> Result < Option < T > , < T as TryFrom < MapRef > > ::Error >
where
< T as TryFrom < MapRef > > ::Error : From < MapError > ,
{
self . maps
self . maps
. get ( name )
. get ( name )
. map ( | lock | {
. ok_or_else ( | | MapError ::NotFound {
T ::try_from ( lock . try_read ( ) . map_err ( | _ | MapError ::BorrowError {
name : name . to_owned ( ) ,
name : name . to_owned ( ) ,
} ) ? )
} )
} )
. transpose ( )
. and_then ( | lock | {
lock . try_read ( ) . map_err ( | _ | MapError ::BorrowError {
name : name . to_owned ( ) ,
} )
} )
}
}
pub fn map_mut < T : TryFrom < MapRefMut > > (
pub fn map_mut ( & self , name : & str ) -> Result < MapRefMut , MapError > {
& self ,
name : & str ,
) -> Result < Option < T > , < T as TryFrom < MapRefMut > > ::Error >
where
< T as TryFrom < MapRefMut > > ::Error : From < MapError > ,
{
self . maps
self . maps
. get ( name )
. get ( name )
. map ( | lock | {
. ok_or_else ( | | MapError ::NotFound {
T ::try_from ( lock . try_write ( ) . map_err ( | _ | MapError ::BorrowError {
name : name . to_owned ( ) ,
name : name . to_owned ( ) ,
} ) ? )
} )
} )
. transpose ( )
. and_then ( | lock | {
lock . try_write ( ) . map_err ( | _ | MapError ::BorrowError {
name : name . to_owned ( ) ,
} )
} )
}
}
pub fn maps < ' a > ( & ' a self ) -> impl Iterator < Item = ( & ' a str , Result < MapRef , MapError > ) > + ' a {
pub fn maps < ' a > ( & ' a self ) -> impl Iterator < Item = ( & ' a str , Result < MapRef , MapError > ) > + ' a {