ruma_api_macros: Use find_map in Response::newtype_body_field

This commit is contained in:
Jonas Platte 2019-11-16 15:40:26 +01:00
parent 18ed83ef76
commit 772c378fe2
No known key found for this signature in database
GPG Key ID: 7D261D771D915378

View File

@ -83,16 +83,9 @@ impl Response {
/// Gets the newtype body field, if this response has one.
pub fn newtype_body_field(&self) -> Option<&Field> {
for response_field in self.fields.iter() {
match *response_field {
ResponseField::NewtypeBody(ref field) => {
return Some(field);
}
_ => continue,
}
}
None
self.fields
.iter()
.find_map(ResponseField::as_newtype_body_field)
}
}
@ -257,6 +250,11 @@ impl ResponseField {
}
}
/// Whether or not this response field is a newtype body kind.
fn is_newtype_body(&self) -> bool {
self.as_newtype_body_field().is_some()
}
/// Return the contained field if this response field is a body kind.
fn as_body_field(&self) -> Option<&Field> {
match self {
@ -265,11 +263,11 @@ impl ResponseField {
}
}
/// Whether or not this response field is a newtype body kind.
fn is_newtype_body(&self) -> bool {
match *self {
ResponseField::NewtypeBody(..) => true,
_ => false,
/// Return the contained field if this response field is a newtype body kind.
fn as_newtype_body_field(&self) -> Option<&Field> {
match self {
ResponseField::NewtypeBody(field) => Some(field),
_ => None,
}
}
}