ruma_api_macros: Use find_map in Response::newtype_body_field
This commit is contained in:
parent
18ed83ef76
commit
772c378fe2
@ -83,16 +83,9 @@ impl Response {
|
|||||||
|
|
||||||
/// Gets the newtype body field, if this response has one.
|
/// Gets the newtype body field, if this response has one.
|
||||||
pub fn newtype_body_field(&self) -> Option<&Field> {
|
pub fn newtype_body_field(&self) -> Option<&Field> {
|
||||||
for response_field in self.fields.iter() {
|
self.fields
|
||||||
match *response_field {
|
.iter()
|
||||||
ResponseField::NewtypeBody(ref field) => {
|
.find_map(ResponseField::as_newtype_body_field)
|
||||||
return Some(field);
|
|
||||||
}
|
|
||||||
_ => continue,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
None
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -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.
|
/// Return the contained field if this response field is a body kind.
|
||||||
fn as_body_field(&self) -> Option<&Field> {
|
fn as_body_field(&self) -> Option<&Field> {
|
||||||
match self {
|
match self {
|
||||||
@ -265,11 +263,11 @@ impl ResponseField {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Whether or not this response field is a newtype body kind.
|
/// Return the contained field if this response field is a newtype body kind.
|
||||||
fn is_newtype_body(&self) -> bool {
|
fn as_newtype_body_field(&self) -> Option<&Field> {
|
||||||
match *self {
|
match self {
|
||||||
ResponseField::NewtypeBody(..) => true,
|
ResponseField::NewtypeBody(field) => Some(field),
|
||||||
_ => false,
|
_ => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user