What are the differences between Rust's `String` and `str`?

前端 未结 9 845
醉梦人生
醉梦人生 2020-11-22 05:11

Why does Rust have String and str? What are the differences between String and str? When does one use String

9条回答
  •  再見小時候
    2020-11-22 05:47

    str, only used as &str, is a string slice, a reference to a UTF-8 byte array.

    String is what used to be ~str, a growable, owned UTF-8 byte array.

提交回复
热议问题