From c307763df8a232e3636b2efd47e5cbea33965f18 Mon Sep 17 00:00:00 2001 From: aka686 Date: Fri, 27 Feb 2026 00:35:08 +0800 Subject: [PATCH] refactor: simplify Option utility functions with idiomatic Rust - select_option_by_clone: use or_else instead of match - merge_option: use Option::or instead of match - No behavior change, just more idiomatic --- src/utils.rs | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/utils.rs b/src/utils.rs index a9753493..17d94976 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -19,10 +19,7 @@ pub fn select_option_by_clone(a: &Option, b: &Option) -> Option where T: Clone, { - match a { - Some(_a) => Some(_a.clone()), - None => b.clone(), - } + a.as_ref().cloned().or_else(|| b.clone()) } pub fn option_owned_by_clone(a: Option<&T>) -> Option @@ -33,10 +30,7 @@ where } pub fn merge_option(a: Option, b: Option) -> Option { - match a { - Some(v) => Some(v), - None => b, - } + a.or(b) } pub fn get_bool_from_string(s: &Option, default: bool) -> bool {