From 89387c51da218caceb6958f18ded523889ad4b50 Mon Sep 17 00:00:00 2001 From: Filip Tibell Date: Thu, 16 Feb 2023 18:17:56 +0100 Subject: [PATCH] Use unwrap or default where possible --- packages/lib/src/globals/stdio.rs | 8 ++++---- packages/lib/src/globals/task.rs | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/lib/src/globals/stdio.rs b/packages/lib/src/globals/stdio.rs index ca0c59d..927cc70 100644 --- a/packages/lib/src/globals/stdio.rs +++ b/packages/lib/src/globals/stdio.rs @@ -49,8 +49,8 @@ fn prompt(options: PromptOptions) -> LuaResult { PromptKind::Text => { let input: String = Input::with_theme(&theme) .allow_empty(true) - .with_prompt(options.text.unwrap_or("".to_string())) - .with_initial_text(options.default_string.unwrap_or("".to_string())) + .with_prompt(options.text.unwrap_or_default()) + .with_initial_text(options.default_string.unwrap_or_default()) .interact_text()?; Ok(PromptResult::String(input)) } @@ -66,7 +66,7 @@ fn prompt(options: PromptOptions) -> LuaResult { } PromptKind::Select => { let chosen = Select::with_theme(&prompt_theme()) - .with_prompt(&options.text.unwrap_or("".to_string())) + .with_prompt(&options.text.unwrap_or_default()) .items(&options.options.expect("Missing options in prompt options")) .interact_opt()?; Ok(match chosen { @@ -76,7 +76,7 @@ fn prompt(options: PromptOptions) -> LuaResult { } PromptKind::MultiSelect => { let chosen = MultiSelect::with_theme(&prompt_theme()) - .with_prompt(&options.text.unwrap_or("".to_string())) + .with_prompt(&options.text.unwrap_or_default()) .items(&options.options.expect("Missing options in prompt options")) .interact_opt()?; Ok(match chosen { diff --git a/packages/lib/src/globals/task.rs b/packages/lib/src/globals/task.rs index 126ec76..ce38641 100644 --- a/packages/lib/src/globals/task.rs +++ b/packages/lib/src/globals/task.rs @@ -66,7 +66,7 @@ pub fn create(lua: &'static Lua) -> LuaResult> { let sched = lua .app_data_ref::<&TaskScheduler>() .expect(ERR_MISSING_SCHEDULER); - sched.schedule_wait(secs.unwrap_or(0f64), LuaValue::Thread(thread)) + sched.schedule_wait(secs.unwrap_or_default(), LuaValue::Thread(thread)) }, )? .build_readonly()?,