# Rust: error[E0608]: cannot index into a value of type `HashSet<i32>` / `String` cannot be indexed by `{integer}`

**Code:** `E0608: cannot index into a value of type` · **Category:** Rust · **Seen on:** Rust

The type doesn't support `[]` indexing (or not with that index type).

## Meaning

Strings can't be indexed by integer (UTF-8): use `.chars().nth(i)`, `.as_bytes()[i]`, or slicing `&s[0..1]` (byte ranges). HashSet/Option/iterators don't implement Index. Use `get()`, `iter().nth()`, or convert to Vec. HashMap needs `map["key"]` with `&str` key types matching.

## Common causes

- `string[0]` indexing
- HashSet/BTreeSet/Option indexing
- Iterator `iter[0]`
- Index type mismatch (`i32` instead of `usize`)
- Custom types without `Index`

## Quick fix

1. `s.chars().nth(0)` / `s.as_bytes()[0]` / `&s[..1]`
2. `v.get(i)` returns Option
3. Cast `i as usize` for Vec indexing

## Detailed fix by platform

### Rust

1. `let first = s.chars().next();`

## How to diagnose

1. **Type** — Indexable?
2. **Index** — usize?
3. **Alternative** — chars/get?

---
Source: [WhatIsMyError](https://whatismyerror.com/errors/rust/e0608-cannot-index-into-a-value)
