From c41a7c4102f6c29e05630a8a4d3a32fb3a924af0 Mon Sep 17 00:00:00 2001 From: Mmh-zxz Date: Sun, 14 Jan 2024 13:11:52 +0800 Subject: [PATCH] Replace map_or_else with unwrap_or and add a test for get_value_u32 --- src/lib.rs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index d61c6e4..62ad3f8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -111,7 +111,7 @@ pub(crate) mod properties { value .to_string() .parse::() - .map_or_else(|_e| default, |v| v) + .unwrap_or(default) }) } @@ -123,7 +123,7 @@ pub(crate) mod properties { value .to_string() .parse::() - .map_or_else(|_e| default, |v| v) + .unwrap_or(default) }) } } @@ -182,7 +182,8 @@ mod tests { #[cfg(test)] mod test_props { use crate::api::constants::ENV_NACOS_CLIENT_NAMING_PUSH_EMPTY_PROTECTION; - use crate::properties::{get_value, get_value_bool}; + use crate::api::constants::ENV_NACOS_CLIENT_COMMON_THREAD_CORES; + use crate::properties::{get_value, get_value_bool, get_value_u32}; #[test] fn test_get_value() { @@ -195,6 +196,12 @@ mod test_props { let v = get_value_bool(ENV_NACOS_CLIENT_NAMING_PUSH_EMPTY_PROTECTION, true); assert_eq!(v, true); } + + #[test] + fn test_get_value_u32() { + let v = get_value_u32(ENV_NACOS_CLIENT_COMMON_THREAD_CORES, 91); + assert_eq!(v, 91); + } } #[cfg(test)]