2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Rustの配列やらVecやら&strやらStringやらについての備忘録

Last updated at Posted at 2022-01-05
  • array
    • 全てのデータがスタックにある
    • 値の変更は可能だが固定長
  • Vec
    • データそのものはヒープにある
    • スタックには先頭データへのポインタ、データ数、キャパシティがある
    • データを変更したり追加したりできる
    • キャパシティを超えるデータを追加しようとするとヒープの別の空いている場所に移動されることがある
  • スライス
    • Vecやarrayなど、連続するデータを参照するための型
    • Vecとは違い、先頭データへのポインタとデータ数のみをスタックに持つ
    • 可変スライスと不変スライスがあり、可変スライスのみデータの変更が可能
  • u8
    • 8bitのデータをもつ型
  • char
    • 4バイトのUnicodeスカラー値を表現するデータを持つ型
  • &str
    • u8の不変スライス
    • マルチバイト文字は複数のデータで一文字を表現する
  • 文字列リテラル
    • ハードコードされた文字列
    • 型としては&strと同じ
  • String
    • 中身はu8のVec
    • ただし、インデックスによるアクセスはできない
  • Chars
    • char型が取り出されるイテレータ
2
1
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?