Split address reach error and node reach error (#1013)

* Split address reach error and node reach error

* Small comments about order of operatoins

* Minor doc change
This commit is contained in:
Pierre Krieger
2019-03-20 20:28:55 +01:00
committed by GitHub
parent 3f05de6d7c
commit 34db72a080
3 changed files with 57 additions and 10 deletions

View File

@ -214,6 +214,20 @@ fn build_struct(ast: &DeriveInput, data_struct: &DataStruct) -> TokenStream {
})
};
// Build the list of statements to put in the body of `inject_addr_reach_failure()`.
let inject_addr_reach_failure_stmts = {
data_struct.fields.iter().enumerate().filter_map(move |(field_n, field)| {
if is_ignored(&field) {
return None;
}
Some(match field.ident {
Some(ref i) => quote!{ self.#i.inject_addr_reach_failure(peer_id, addr, error); },
None => quote!{ self.#field_n.inject_addr_reach_failure(peer_id, addr, error); },
})
})
};
// Build the list of statements to put in the body of `inject_dial_failure()`.
let inject_dial_failure_stmts = {
data_struct.fields.iter().enumerate().filter_map(move |(field_n, field)| {
@ -222,8 +236,8 @@ fn build_struct(ast: &DeriveInput, data_struct: &DataStruct) -> TokenStream {
}
Some(match field.ident {
Some(ref i) => quote!{ self.#i.inject_dial_failure(peer_id, addr, error); },
None => quote!{ self.#field_n.inject_dial_failure(peer_id, addr, error); },
Some(ref i) => quote!{ self.#i.inject_dial_failure(peer_id); },
None => quote!{ self.#field_n.inject_dial_failure(peer_id); },
})
})
};
@ -396,7 +410,12 @@ fn build_struct(ast: &DeriveInput, data_struct: &DataStruct) -> TokenStream {
}
#[inline]
fn inject_dial_failure(&mut self, peer_id: Option<&#peer_id>, addr: &#multiaddr, error: &dyn std::error::Error) {
fn inject_addr_reach_failure(&mut self, peer_id: Option<&#peer_id>, addr: &#multiaddr, error: &dyn std::error::Error) {
#(#inject_addr_reach_failure_stmts);*
}
#[inline]
fn inject_dial_failure(&mut self, peer_id: &#peer_id) {
#(#inject_dial_failure_stmts);*
}