From 2261067251a705bbb77edae1f5542031d7598c59 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Sat, 16 Nov 2019 15:58:48 +0100 Subject: [PATCH] ruma_api_macros: Use find_map in Request::newtype_body_field --- ruma-api-macros/src/api/request.rs | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/ruma-api-macros/src/api/request.rs b/ruma-api-macros/src/api/request.rs index 457c799d..a19b83b9 100644 --- a/ruma-api-macros/src/api/request.rs +++ b/ruma-api-macros/src/api/request.rs @@ -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)