]> git.lizzy.rs Git - rust.git/commitdiff
Update docs for `manual_split_once`
authorJason Newcomb <jsnewcomb@pm.me>
Sun, 15 Aug 2021 20:27:59 +0000 (16:27 -0400)
committerJason Newcomb <jsnewcomb@pm.me>
Mon, 16 Aug 2021 13:35:03 +0000 (09:35 -0400)
clippy_lints/src/methods/mod.rs

index 15ad0325006eb62dcc31de8151b091c71cd8bcf8..b6438bce8746e7c86deca4d61c35716dc9a5d33e 100644 (file)
 }
 
 declare_clippy_lint! {
-    /// **What it does:** Checks for usages of `splitn(2, _)`
+    /// **What it does:** Checks for usages of `str::splitn(2, _)`
     ///
-    /// **Why is this bad?** `split_once` is clearer.
+    /// **Why is this bad?** `split_once` is both clearer in intent and slightly more efficient.
     ///
     /// **Known problems:** None.
     ///
     /// **Example:**
     ///
-    /// ```rust
+    /// ```rust,ignore
     /// // Bad
-    /// let some_str = "name=value";
-    /// let mut iter = some_str.splitn(2, '=');
-    /// let name = iter.next().unwrap();
-    /// let value = iter.next().unwrap_or("");
+    ///  let (key, value) = _.splitn(2, '=').next_tuple()?;
+    ///  let value = _.splitn(2, '=').nth(1)?;
     ///
     /// // Good
-    /// let some_str = "name=value";
-    /// let (name, value) = some_str.split_once('=').unwrap_or((some_str, ""));
+    /// let (key, value) = _.split_once('=')?;
+    /// let value = _.split_once('=')?.1;
     /// ```
     pub MANUAL_SPLIT_ONCE,
     complexity,