GeezerVison is showing github.com — id: rustfmt meta_client.rs and drop expect() in tags search parser (#… · developing-today/code@6f00e7e
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: pkgs/id/src/meta_client.rs +3-3Lines changed: 3 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -53,9 +53,9 @@ pub fn expect_ok(resp: MetaResponse) -> Result<MetaResponse> { |
53 | 53 | /// limit instead. Any other read failure passes through unchanged. |
54 | 54 | pub fn capped_response_error(err: ReadToEndError) -> anyhow::Error { |
55 | 55 | match err { |
56 | | - ReadToEndError::TooLong => anyhow::anyhow!( |
57 | | - "response too large: exceeds the {MAX_RESPONSE_BYTES}-byte limit" |
58 | | - ), |
| 56 | + ReadToEndError::TooLong => { |
| 57 | + anyhow::anyhow!("response too large: exceeds the {MAX_RESPONSE_BYTES}-byte limit") |
| 58 | + } |
59 | 59 | other => other.into(), |
60 | 60 | } |
61 | 61 | } |
|
Collapse file
Copy file name to clipboardExpand all lines: pkgs/id/src/tags.rs +9-3Lines changed: 9 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -1474,14 +1474,18 @@ pub fn parse_search_query(input: &str) -> Vec<SearchTerm> { |
1474 | 1474 |
|
1475 | 1475 | // Byte index into `input`. It only ever advances by whole chars, so it |
1476 | 1476 | // always rests on a char boundary and slicing stays valid even when a |
1477 | | - // separator is a multi-byte whitespace char such as NBSP (U+00A0). |
| 1477 | + // separator is a multi-byte whitespace char such as NBSP (U+00A0). The |
| 1478 | + // loops below guard on `i < input.len()`, so `chars().next()` is always |
| 1479 | + // `Some` there; the let-else form keeps that invariant panic-free. |
1478 | 1480 | let mut i = 0; |
1479 | 1481 |
|
1480 | 1482 | while i < input.len() { |
1481 | 1483 | // Skip whitespace: any `char::is_whitespace` char separates terms, |
1482 | 1484 | // not only the ASCII space. |
1483 | 1485 | while i < input.len() { |
1484 | | - let ch = input[i..].chars().next().expect("i is a char boundary"); |
| 1486 | + let Some(ch) = input[i..].chars().next() else { |
| 1487 | + break; |
| 1488 | + }; |
1485 | 1489 | if !ch.is_whitespace() { |
1486 | 1490 | break; |
1487 | 1491 | } |
@@ -1496,7 +1500,9 @@ pub fn parse_search_query(input: &str) -> Vec<SearchTerm> { |
1496 | 1500 | let start = i; |
1497 | 1501 | let mut in_quotes = false; |
1498 | 1502 | while i < input.len() { |
1499 | | - let ch = input[i..].chars().next().expect("i is a char boundary"); |
| 1503 | + let Some(ch) = input[i..].chars().next() else { |
| 1504 | + break; |
| 1505 | + }; |
1500 | 1506 | if ch == '"' { |
1501 | 1507 | in_quotes = !in_quotes; |
1502 | 1508 | i += 1; |
|