Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace map_or_else with unwrap_or and add a test for get_value_u32 #212

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,7 @@ pub(crate) mod properties {
Key: AsRef<str>,
{
PROPERTIES.get(key.as_ref()).map_or(default, |value| {
value
.to_string()
.parse::<u32>()
.map_or_else(|_e| default, |v| v)
value.to_string().parse::<u32>().unwrap_or(default)
})
}

Expand All @@ -120,10 +117,7 @@ pub(crate) mod properties {
Key: AsRef<str>,
{
PROPERTIES.get(key.as_ref()).map_or(default, |value| {
value
.to_string()
.parse::<bool>()
.map_or_else(|_e| default, |v| v)
value.to_string().parse::<bool>().unwrap_or(default)
})
}
}
Expand Down Expand Up @@ -182,7 +176,7 @@ 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::properties::{get_value, get_value_bool, get_value_u32};

#[test]
fn test_get_value() {
Expand All @@ -195,6 +189,13 @@ 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 not_exist_key = "MUST_NOT_EXIST";
let v = get_value_u32(not_exist_key, 91);
assert_eq!(v, 91);
}
}

#[cfg(test)]
Expand Down
Loading