Skip to content

Commit 11d28ee

Browse files
committed
Update docs for manual_split_once
1 parent 5a1f452 commit 11d28ee

File tree

1 file changed

+12
-8
lines changed
  • clippy_lints/src/methods

1 file changed

+12
-8
lines changed

clippy_lints/src/methods/mod.rs

+12-8
Original file line numberDiff line numberDiff line change
@@ -1774,24 +1774,28 @@ declare_clippy_lint! {
17741774
}
17751775

17761776
declare_clippy_lint! {
1777-
/// **What it does:** Checks for usages of `splitn(2, _)`
1777+
/// **What it does:** Checks for usages of `str::splitn(2, _)`
17781778
///
1779-
/// **Why is this bad?** `split_once` is clearer.
1779+
/// **Why is this bad?** `split_once` is both clearer in intent and slightly more efficient.
17801780
///
17811781
/// **Known problems:** None.
17821782
///
17831783
/// **Example:**
17841784
///
17851785
/// ```rust
17861786
/// // Bad
1787-
/// let some_str = "name=value";
1788-
/// let mut iter = some_str.splitn(2, '=');
1789-
/// let name = iter.next().unwrap();
1790-
/// let value = iter.next().unwrap_or("");
1787+
/// fn f(s: &str) -> Option<&str> {
1788+
/// let (key, value) = s.splitn(2, '=').next_tuple()?;
1789+
/// let value = s.splitn(2, '=').nth(1)?;
1790+
/// None
1791+
/// }
17911792
///
17921793
/// // Good
1793-
/// let some_str = "name=value";
1794-
/// let (name, value) = some_str.split_once('=').unwrap_or((some_str, ""));
1794+
/// fn f2(s: &str) -> Option<&str> {
1795+
/// let (key, value) = s.splitn(2, '=').next_tuple()?;
1796+
/// let value = s.splitn(2, '=').nth(1)?;
1797+
/// None
1798+
/// }
17951799
/// ```
17961800
pub MANUAL_SPLIT_ONCE,
17971801
complexity,

0 commit comments

Comments
 (0)