2022-02-06 16:43:51 +08:00
|
|
|
$ cargo run
|
|
|
|
Compiling collections v0.1.0 (file:///projects/collections)
|
2024-06-06 21:23:21 +08:00
|
|
|
error[E0277]: the type `str` cannot be indexed by `{integer}`
|
|
|
|
--> src/main.rs:3:16
|
2022-02-06 16:43:51 +08:00
|
|
|
|
|
|
|
|
3 | let h = s1[0];
|
2024-06-06 21:23:21 +08:00
|
|
|
| ^ string indices are ranges of `usize`
|
2022-02-06 16:43:51 +08:00
|
|
|
|
|
2024-06-06 21:23:21 +08:00
|
|
|
= help: the trait `SliceIndex<str>` is not implemented for `{integer}`, which is required by `String: Index<_>`
|
|
|
|
= note: you can use `.chars().nth()` or `.bytes().nth()`
|
|
|
|
for more information, see chapter 8 in The Book: <https://doc.rust-lang.org/book/ch08-02-strings.html#indexing-into-strings>
|
|
|
|
= help: the trait `SliceIndex<[_]>` is implemented for `usize`
|
|
|
|
= help: for that trait implementation, expected `[_]`, found `str`
|
|
|
|
= note: required for `String` to implement `Index<{integer}>`
|
2022-02-06 16:43:51 +08:00
|
|
|
|
|
|
|
For more information about this error, try `rustc --explain E0277`.
|
2024-06-06 21:23:21 +08:00
|
|
|
error: could not compile `collections` (bin "collections") due to 1 previous error
|