aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authoracdenisSK <[email protected]>2017-07-20 18:34:55 +0200
committeracdenisSK <[email protected]>2017-07-20 18:34:55 +0200
commitf5a97d43b467130fd97af8c8a0dd1bbf0e7f5326 (patch)
tree1736d559f602bd2dcb094b94da2b7b7732c7a8c2 /src
parentAdd an actual way to fetch audit log entries from a guild (diff)
downloadserenity-f5a97d43b467130fd97af8c8a0dd1bbf0e7f5326.tar.xz
serenity-f5a97d43b467130fd97af8c8a0dd1bbf0e7f5326.zip
Utilise the newly stabilised loop-with-break-value
Diffstat (limited to 'src')
-rw-r--r--src/model/guild/audit_log.rs20
-rw-r--r--src/voice/connection.rs32
2 files changed, 19 insertions, 33 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() })
}
}
diff --git a/src/voice/connection.rs b/src/voice/connection.rs
index 801c871..ced6a79 100644
--- a/src/voice/connection.rs
+++ b/src/voice/connection.rs
@@ -71,27 +71,19 @@ impl Connection {
client.send_json(&payload::build_identify(&info))?;
- let hello = {
- let hello;
-
- loop {
- match client.recv_json(VoiceEvent::decode)? {
- VoiceEvent::Hello(received_hello) => {
- hello = received_hello;
-
- break;
- },
- VoiceEvent::Heartbeat(_) => continue,
- other => {
- debug!("[Voice] Expected hello/heartbeat; got: {:?}",
- other);
-
- return Err(Error::Voice(VoiceError::ExpectedHandshake));
- },
- }
+ let hello = loop {
+ match client.recv_json(VoiceEvent::decode)? {
+ VoiceEvent::Hello(received_hello) => {
+ break received_hello;
+ },
+ VoiceEvent::Heartbeat(_) => continue,
+ other => {
+ debug!("[Voice] Expected hello/heartbeat; got: {:?}",
+ other);
+
+ return Err(Error::Voice(VoiceError::ExpectedHandshake));
+ },
}
-
- hello
};
if !has_valid_mode(&hello.modes) {