2 Checks for the `as_bytes` method called on string literals
3 that contain only ASCII characters.
6 Byte string literals (e.g., `b"foo"`) can be used
7 instead. They are shorter but less discoverable than `as_bytes()`.
10 `"str".as_bytes()` and the suggested replacement of `b"str"` are not
11 equivalent because they have different types. The former is `&[u8]`
12 while the latter is `&[u8; 3]`. That means in general they will have a
13 different set of methods and different trait implementations.
18 f("...".as_bytes().to_owned()); // works
19 f(b"...".to_owned()); // does not work, because arg is [u8; 3] not Vec<u8>
21 fn g(r: impl std::io::Read) {}
23 g("...".as_bytes()); // works
24 g(b"..."); // does not work
27 The actual equivalent of `"str".as_bytes()` with the same type is not
28 `b"str"` but `&b"str"[..]`, which is a great deal of punctuation and not
29 more readable than a function call.
33 let bstr = "a byte string".as_bytes();
38 let bstr = b"a byte string";