Skip to content

Commit

Permalink
tiny bit more idiomatic param parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
eli-r-ph committed Feb 23, 2025
1 parent 54433dc commit 12347d0
Showing 1 changed file with 8 additions and 14 deletions.
22 changes: 8 additions & 14 deletions rust/property-defs-rs/src/api/v1/routing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,21 +109,15 @@ async fn project_property_definitions_handler(
.get("event_names")
.map(|raw| raw.split(",").map(|s| s.trim().to_string()).collect());

let limit: i32 = match params.get("limit") {
Some(s) => match s.parse::<i32>().ok() {
Some(val) => val,
_ => DEFAULT_QUERY_LIMIT,
},
_ => DEFAULT_QUERY_LIMIT,
};
let limit: i32 = params.get("limit").map_or_else(
|| DEFAULT_QUERY_LIMIT,
|s| s.parse::<i32>().unwrap_or_else(|_| DEFAULT_QUERY_LIMIT),
);

let offset: i32 = match params.get("offset") {
Some(s) => match s.parse::<i32>().ok() {
Some(val) => val,
_ => DEFAULT_QUERY_OFFSET,
},
_ => DEFAULT_QUERY_OFFSET,
};
let offset: i32 = params.get("offset").map_or_else(
|| DEFAULT_QUERY_OFFSET,
|s| s.parse::<i32>().unwrap_or_else(|_| DEFAULT_QUERY_OFFSET),
);

let order_by_verified = true; // default behavior

Expand Down

0 comments on commit 12347d0

Please sign in to comment.