Skip to content

Commit

Permalink
Use unwrap_or_else instead of unwrap_or
Browse files Browse the repository at this point in the history
  • Loading branch information
tapnisu committed Mar 9, 2024
1 parent 6b228d0 commit b73e42c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 18 deletions.
36 changes: 19 additions & 17 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,29 +14,31 @@ use teloxide::prelude::*;
#[tokio::main]
async fn main() {
let args = Cli::parse();
let config_path = args.config_path.unwrap_or(format!(
"{}/.config/dsc-tg-forwarder/config.yml",
home::home_dir().unwrap().display()
));
let config_path = args.config_path.unwrap_or_else(|| {
format!(
"{}/.config/dsc-tg-forwarder/config.yml",
home::home_dir().unwrap().display()
)
});
let config = parse_config(&config_path);

let discord_token = args.discord_token.unwrap_or(
let discord_token = args.discord_token.unwrap_or_else(|| {
config
.discord_token
.unwrap_or_else(|| env::var("DISCORD_TOKEN").expect("Discord token wasn't supplied")),
);
.unwrap_or_else(|| env::var("DISCORD_TOKEN").expect("Discord token wasn't supplied"))
});

let telegram_token =
args.telegram_token
.unwrap_or(config.telegram_token.unwrap_or_else(|| {
env::var("TELEGRAM_TOKEN").expect("Telegram token wasn't supplied")
}));
let telegram_token = args.telegram_token.unwrap_or_else(|| {
config
.telegram_token
.unwrap_or_else(|| env::var("TELEGRAM_TOKEN").expect("Telegram token wasn't supplied"))
});

let output_chat_id =
args.output_chat_id
.unwrap_or(config.output_chat_id.unwrap_or_else(|| {
env::var("OUTPUT_CHAT_ID").expect("Output chat id wasn't supplied")
}));
let output_chat_id = args.output_chat_id.unwrap_or_else(|| {
config
.output_chat_id
.unwrap_or_else(|| env::var("OUTPUT_CHAT_ID").expect("Output chat id wasn't supplied"))
});

// Login with a bot token from the environment
let client = Client::builder(discord_token)
Expand Down
2 changes: 1 addition & 1 deletion src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ pub fn format_embed(embed: &Embed) -> String {
format!(
"[{}]({})\n",
title.escape_markdown_v2(),
embed.url.to_owned().unwrap_or("".to_string())
embed.url.to_owned().unwrap_or_else(|| "".to_string())
)
});

Expand Down

0 comments on commit b73e42c

Please sign in to comment.