I am trying to extend the crate rust-snmp. From what I can tell, it cannot walk mibs. It can perform a getnext and a getbulk but does not continue to do so until reaching the next column. Below is my code attempting to implement this.
fn get_bulk(addr: &'static str, non_repeat: u32, max_repetitions: u32, oids: Vec<&'static [u32]>) {
/// The community string and timeout need to be moved to main
///
/// non_repeat is the number of non-repeaters
let community = b"maybe_public";
let timeout = Duration::from_secs(10);
/// Think in terms of row from table and each oid a column in the table
/// Which they actually are in
let mut row = 1u32;
let cols = *&oids.len() as usize;
let handle = thread::spawn( move || {
let mut mutable_oids = oids.clone();
let mut sess = SyncSession::new(
addr, community, Some(timeout), 0).unwrap();
let response = sess.getbulk(
mutable_oids.clone(),
non_repeat, max_repetitions).unwrap();
let mut col = 0_usize;
for (name, val) in response.varbinds {
if col == cols {
col = 0;
row += 1;
}
println!("{}. {} {} => {:?}", row, addr, name, val);
/// Find the last table row and add those each column's
/// objectidentifiers to the new oids
if row == max_repetitions {
let returned = name.to_string();
let temp = &oids[col].to_vec();
let oid: String = temp.iter().map(|x| x.to_string() + ".").collect();
if returned.starts_with(&oid) {
let split = returned.split('.').collect::<Vec<&str>>();
let next_getbulk = split.into_iter()
.map(|c| c.parse::<u32>().unwrap())
.collect::<Vec<u32>>();
println!("{:?}", next_getbulk.as_slice());
mutable_oids[col] = next_getbulk.as_slice();
}
}
col += 1;
}
});
handle.join();
}
As you can easily imagine, I get borrowed value does not live long enough with next_getbulk .as_slice() as soon as I am out of the if block. I've tried every way I can think of to get around this borrow error and have given up enough and posted for help.