|
|
@ -1,6 +1,5 @@
|
|
|
|
use std::{
|
|
|
|
use std::{
|
|
|
|
collections::HashMap,
|
|
|
|
collections::HashMap,
|
|
|
|
convert::TryFrom,
|
|
|
|
|
|
|
|
error::Error,
|
|
|
|
error::Error,
|
|
|
|
fs, io,
|
|
|
|
fs, io,
|
|
|
|
path::{Path, PathBuf},
|
|
|
|
path::{Path, PathBuf},
|
|
|
@ -185,21 +184,20 @@ impl Bpf {
|
|
|
|
ret
|
|
|
|
ret
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub fn program<'a, T: TryFrom<&'a Program>>(
|
|
|
|
pub fn program(&self, name: &str) -> Result<&Program, ProgramError> {
|
|
|
|
&'a self,
|
|
|
|
self.programs
|
|
|
|
name: &str,
|
|
|
|
.get(name)
|
|
|
|
) -> Result<Option<T>, <T as TryFrom<&'a Program>>::Error> {
|
|
|
|
.ok_or_else(|| ProgramError::NotFound {
|
|
|
|
self.programs.get(name).map(|p| T::try_from(p)).transpose()
|
|
|
|
name: name.to_owned(),
|
|
|
|
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub fn program_mut<'a, T: TryFrom<&'a mut Program>>(
|
|
|
|
pub fn program_mut(&mut self, name: &str) -> Result<&mut Program, ProgramError> {
|
|
|
|
&'a mut self,
|
|
|
|
|
|
|
|
name: &str,
|
|
|
|
|
|
|
|
) -> Result<Option<T>, <T as TryFrom<&'a mut Program>>::Error> {
|
|
|
|
|
|
|
|
self.programs
|
|
|
|
self.programs
|
|
|
|
.get_mut(name)
|
|
|
|
.get_mut(name)
|
|
|
|
.map(|p| T::try_from(p))
|
|
|
|
.ok_or_else(|| ProgramError::NotFound {
|
|
|
|
.transpose()
|
|
|
|
name: name.to_owned(),
|
|
|
|
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub fn programs(&self) -> impl Iterator<Item = &Program> {
|
|
|
|
pub fn programs(&self) -> impl Iterator<Item = &Program> {
|
|
|
|