diff options
| author | acdenisSK <[email protected]> | 2017-07-20 18:34:55 +0200 |
|---|---|---|
| committer | acdenisSK <[email protected]> | 2017-07-20 18:34:55 +0200 |
| commit | f5a97d43b467130fd97af8c8a0dd1bbf0e7f5326 (patch) | |
| tree | 1736d559f602bd2dcb094b94da2b7b7732c7a8c2 /src/model | |
| parent | Add an actual way to fetch audit log entries from a guild (diff) | |
| download | serenity-f5a97d43b467130fd97af8c8a0dd1bbf0e7f5326.tar.xz serenity-f5a97d43b467130fd97af8c8a0dd1bbf0e7f5326.zip | |
Utilise the newly stabilised loop-with-break-value
Diffstat (limited to 'src/model')
| -rw-r--r-- | src/model/guild/audit_log.rs | 20 |
1 files changed, 7 insertions, 13 deletions
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<V: MapAccess<'de>>(self, mut map: V) -> Result<AuditLogs, V::Error> { - 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::<Vec<AuditLogEntry>>()?; } - - audit_log_entries = Some(map.next_value()?); } } - } - - let entries: Vec<AuditLogEntry> = 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() }) } } |