Skip to content

Commit 7bf1c05

Browse files
committed
Use the new "let else" construct
Also switched to "or_else" for one construct since we don't have `inspect_err` yet. rust-lang/rust#91345
1 parent 9e657b5 commit 7bf1c05

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

bot.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,9 @@ async fn get_channel_info(ctx: &Context, voice_state: &VoiceState) -> Option<(Ch
4141
.ok()?;
4242

4343
// Ignore all channels other than voice channels.
44-
let guild_channel = match channel {
45-
Channel::Guild(guild_channel) => guild_channel,
46-
_ => {
47-
println!("Got something other than a guild channel");
48-
return None;
49-
}
44+
let Channel::Guild(guild_channel) = channel else {
45+
println!("Got something other than a guild channel");
46+
return None;
5047
};
5148
if guild_channel.kind != ChannelType::Voice {
5249
println!("Got something other than a voice channel");
@@ -55,15 +52,16 @@ async fn get_channel_info(ctx: &Context, voice_state: &VoiceState) -> Option<(Ch
5552
println!("Got event for channel called \"{}\"", guild_channel.name());
5653

5754
// Find out how many folks are in that voice channel.
58-
let member_count = match guild_channel.members(&ctx).await {
59-
Ok(members) => members.len(),
60-
Err(why) => {
55+
let members = guild_channel
56+
.members(&ctx)
57+
.await
58+
.or_else(|why| {
6159
println!("Failed to get member count: {:?}", why);
62-
return None;
63-
}
64-
};
60+
return Err(why);
61+
})
62+
.ok()?;
6563

66-
Some((id, member_count))
64+
Some((id, members.len()))
6765
}
6866

6967
#[async_trait]
@@ -132,9 +130,11 @@ async fn get_discord_token() -> String {
132130
return token;
133131
}
134132
let token_file = env::var("DISCORD_TOKEN_FILE").expect("Could not read DISCORD_TOKEN_FILE");
135-
let contents = tokio::fs::read_to_string(&token_file).await.unwrap_or_else(|why| {
136-
panic!("Failed to read {}: {:?}", token_file.as_str(), why);
137-
});
133+
let contents = tokio::fs::read_to_string(&token_file)
134+
.await
135+
.unwrap_or_else(|why| {
136+
panic!("Failed to read {}: {:?}", token_file.as_str(), why);
137+
});
138138
contents
139139
}
140140

0 commit comments

Comments
 (0)