ruma_api_macros: Use find_map in Request::newtype_body_field

This commit is contained in:
Jonas Platte 2019-11-16 15:58:48 +01:00
parent d0d1d97ee4
commit 2261067251
No known key found for this signature in database
GPG Key ID: 7D261D771D915378

View File

@ -72,16 +72,9 @@ impl Request {
/// Returns the body field.
pub fn newtype_body_field(&self) -> Option<&Field> {
for request_field in self.fields.iter() {
match *request_field {
RequestField::NewtypeBody(ref field) => {
return Some(field);
}
_ => continue,
}
}
None
self.fields
.iter()
.find_map(RequestField::as_newtype_body_field)
}
/// Produces code for a struct initializer for body fields on a variable named `request`.
@ -353,6 +346,11 @@ impl RequestField {
self.field_of_kind(RequestFieldKind::Body)
}
/// Return the contained field if this request field is a body kind.
fn as_newtype_body_field(&self) -> Option<&Field> {
self.field_of_kind(RequestFieldKind::NewtypeBody)
}
/// Return the contained field if this request field is a path kind.
fn as_path_field(&self) -> Option<&Field> {
self.field_of_kind(RequestFieldKind::Path)