File tree 1 file changed +12
-8
lines changed
1 file changed +12
-8
lines changed Original file line number Diff line number Diff line change @@ -1774,24 +1774,28 @@ declare_clippy_lint! {
1774
1774
}
1775
1775
1776
1776
declare_clippy_lint ! {
1777
- /// **What it does:** Checks for usages of `splitn(2, _)`
1777
+ /// **What it does:** Checks for usages of `str:: splitn(2, _)`
1778
1778
///
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 .
1780
1780
///
1781
1781
/// **Known problems:** None.
1782
1782
///
1783
1783
/// **Example:**
1784
1784
///
1785
1785
/// ```rust
1786
1786
/// // 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
+ /// }
1791
1792
///
1792
1793
/// // 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
+ /// }
1795
1799
/// ```
1796
1800
pub MANUAL_SPLIT_ONCE ,
1797
1801
complexity,
You can’t perform that action at this time.
0 commit comments