From f5a97d43b467130fd97af8c8a0dd1bbf0e7f5326 Mon Sep 17 00:00:00 2001 From: acdenisSK Date: Thu, 20 Jul 2017 18:34:55 +0200 Subject: Utilise the newly stabilised loop-with-break-value --- src/model/guild/audit_log.rs | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) (limited to 'src/model') diff --git a/src/model/guild/audit_log.rs b/src/model/guild/audit_log.rs index 43e4b16..a5097b2 100644 --- a/src/model/guild/audit_log.rs +++ b/src/model/guild/audit_log.rs @@ -204,23 +204,17 @@ impl<'de> Deserialize<'de> for AuditLogs { } fn visit_map>(self, mut map: V) -> Result { - let mut audit_log_entries = None; - - while let Some(key) = map.next_key()? { - match key { - Field::AuditLogEntries => { - if audit_log_entries.is_some() { - return Err(de::Error::duplicate_field("audit_log_entries")); + let audit_log_entries = loop { + if let Some(key) = map.next_key()? { + match key { + Field::AuditLogEntries => { + break map.next_value::>()?; } - - audit_log_entries = Some(map.next_value()?); } } - } - - let entries: Vec = audit_log_entries.ok_or_else(|| de::Error::missing_field("audit_log_entries"))?; + }; - Ok(AuditLogs { entries: entries.into_iter().map(|entry| (entry.id, entry)).collect() }) + Ok(AuditLogs { entries: audit_log_entries.into_iter().map(|entry| (entry.id, entry)).collect() }) } } -- cgit v1.2.3