about summary refs log tree commit diff
path: root/src/docs/string_from_utf8_as_bytes.txt
diff options
context:
space:
mode:
Diffstat (limited to 'src/docs/string_from_utf8_as_bytes.txt')
-rw-r--r--src/docs/string_from_utf8_as_bytes.txt15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/docs/string_from_utf8_as_bytes.txt b/src/docs/string_from_utf8_as_bytes.txt
new file mode 100644
index 00000000000..9102d73471c
--- /dev/null
+++ b/src/docs/string_from_utf8_as_bytes.txt
@@ -0,0 +1,15 @@
+### What it does
+Check if the string is transformed to byte array and casted back to string.
+
+### Why is this bad?
+It's unnecessary, the string can be used directly.
+
+### Example
+```
+std::str::from_utf8(&"Hello World!".as_bytes()[6..11]).unwrap();
+```
+
+Use instead:
+```
+&"Hello World!"[6..11];
+```
\ No newline at end of file