rust(lint): remove manual implement of map method

Using `if let` expressions in these cases is better expressed
by the map method, and considered idiomatic Rust for this usage.
pull/6304/head
Jason Ish 4 years ago committed by Victor Julien
parent b021726a0d
commit 91402f9fba

@ -479,22 +479,13 @@ named! { pub parse_sa_attribute<&[u8], Vec<SaAttribute>>,
numeric_value: match format.0 { numeric_value: match format.0 {
1 => Some(attribute_length_or_value as u32), 1 => Some(attribute_length_or_value as u32),
0 => { 0 => {
if let Some(_numeric_variable_value) = numeric_variable_value { numeric_variable_value
Some(_numeric_variable_value)
}
else {
None
}
}, },
_ => None, _ => None,
}, },
hex_value: match format.0 { hex_value: match format.0 {
0 => { 0 => {
if let Some(_variable_attribute_value) = variable_attribute_value { variable_attribute_value.map(|_variable_attribute_value| to_hex(_variable_attribute_value))
Some(to_hex(_variable_attribute_value))
} else {
None
}
} }
_ => None, _ => None,
} }

@ -441,10 +441,7 @@ pub fn parse_t123_tpkt(input: &[u8]) -> IResult<&[u8], T123Tpkt, RdpError> {
let opt1: Option<T123TpktChild> = { let opt1: Option<T123TpktChild> = {
match opt!(data, parse_x224_connection_request_class_0) { match opt!(data, parse_x224_connection_request_class_0) {
Ok((_remainder, opt)) => match opt { Ok((_remainder, opt)) => opt.map(T123TpktChild::X224ConnectionRequest),
Some(x) => Some(T123TpktChild::X224ConnectionRequest(x)),
None => None,
},
Err(e) => return Err(e), Err(e) => return Err(e),
} }
}; };
@ -452,10 +449,7 @@ pub fn parse_t123_tpkt(input: &[u8]) -> IResult<&[u8], T123Tpkt, RdpError> {
let opt2: Option<T123TpktChild> = match opt1 { let opt2: Option<T123TpktChild> = match opt1 {
Some(x) => Some(x), Some(x) => Some(x),
None => match opt!(data, parse_x224_connection_confirm_class_0) { None => match opt!(data, parse_x224_connection_confirm_class_0) {
Ok((_remainder, opt)) => match opt { Ok((_remainder, opt)) => opt.map(T123TpktChild::X224ConnectionConfirm),
Some(x) => Some(T123TpktChild::X224ConnectionConfirm(x)),
None => None,
},
Err(e) => return Err(e), Err(e) => return Err(e),
}, },
}; };
@ -463,10 +457,7 @@ pub fn parse_t123_tpkt(input: &[u8]) -> IResult<&[u8], T123Tpkt, RdpError> {
let opt3: Option<T123TpktChild> = match opt2 { let opt3: Option<T123TpktChild> = match opt2 {
Some(x) => Some(x), Some(x) => Some(x),
None => match opt!(data, parse_x223_data_class_0) { None => match opt!(data, parse_x223_data_class_0) {
Ok((_remainder, opt)) => match opt { Ok((_remainder, opt)) => opt.map(T123TpktChild::Data),
Some(x) => Some(T123TpktChild::Data(x)),
None => None,
},
Err(e) => return Err(e), Err(e) => return Err(e),
}, },
}; };
@ -628,19 +619,13 @@ fn parse_x224_connection_confirm(input: &[u8]) -> IResult<&[u8], X224ConnectionC
// it will be one of a response message or a failure message // it will be one of a response message or a failure message
let opt1: Option<NegotiationFromServer> = match opt!(data, parse_negotiation_response) { let opt1: Option<NegotiationFromServer> = match opt!(data, parse_negotiation_response) {
Ok((_remainder, opt)) => match opt { Ok((_remainder, opt)) => opt.map(NegotiationFromServer::Response),
Some(x) => Some(NegotiationFromServer::Response(x)),
None => None,
},
Err(e) => return Err(e), Err(e) => return Err(e),
}; };
let opt2: Option<NegotiationFromServer> = match opt1 { let opt2: Option<NegotiationFromServer> = match opt1 {
Some(x) => Some(x), Some(x) => Some(x),
None => match opt!(data, parse_negotiation_failure) { None => match opt!(data, parse_negotiation_failure) {
Ok((_remainder, opt)) => match opt { Ok((_remainder, opt)) => opt.map(NegotiationFromServer::Failure),
Some(x) => Some(NegotiationFromServer::Failure(x)),
None => None,
},
Err(e) => return Err(e), Err(e) => return Err(e),
}, },
}; };
@ -738,20 +723,14 @@ fn parse_x223_data_class_0(input: &[u8]) -> IResult<&[u8], X223Data, RdpError> {
// //
let opt1: Option<X223DataChild> = match opt!(i3, parse_mcs_connect) { let opt1: Option<X223DataChild> = match opt!(i3, parse_mcs_connect) {
Ok((_remainder, opt)) => match opt { Ok((_remainder, opt)) => opt.map(X223DataChild::McsConnectRequest),
Some(x) => Some(X223DataChild::McsConnectRequest(x)),
None => None,
},
Err(e) => return Err(e), Err(e) => return Err(e),
}; };
let opt2: Option<X223DataChild> = match opt1 { let opt2: Option<X223DataChild> = match opt1 {
Some(x) => Some(x), Some(x) => Some(x),
None => match opt!(i3, parse_mcs_connect_response) { None => match opt!(i3, parse_mcs_connect_response) {
Ok((_remainder, opt)) => match opt { Ok((_remainder, opt)) => opt.map(X223DataChild::McsConnectResponse),
Some(x) => Some(X223DataChild::McsConnectResponse(x)),
None => None,
},
Err(e) => return Err(e), Err(e) => return Err(e),
}, },
}; };

Loading…
Cancel
Save