Use unwrap or default where possible

This commit is contained in:
Filip Tibell 2023-02-16 18:17:56 +01:00
parent 04a47babdd
commit 89387c51da
No known key found for this signature in database
2 changed files with 5 additions and 5 deletions

View file

@ -49,8 +49,8 @@ fn prompt(options: PromptOptions) -> LuaResult<PromptResult> {
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<PromptResult> {
}
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<PromptResult> {
}
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 {

View file

@ -66,7 +66,7 @@ pub fn create(lua: &'static Lua) -> LuaResult<LuaTable<'static>> {
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()?,