Error codes

E0322: strings are immutable

In a terminal: auk explain E0322 prints this page.

On this page

A str can't be changed in place: s[i] reads the i-th char but can't be assigned. Build a new string instead.

Wrong#

auk
fn main() {
  var s = "cat"
  s[0] = 'b'
  print(s)
}

Fixed#

auk
fn main() {
  var s = "cat"
  s = "b" + s[1..3]
  print(s)
}

Common causes#

  • Editing a string char by char: use replace, slices and +, or work on s.chars() and join with str(cs).

Stuck on a word? Try the glossary. Got a compiler error? Look up its code. Improve this page