char型。
成果物
コード
fn main() { let c1 = 'A'; let c2: char = 'B'; println!("{} {}", c1, c2); if c1 == c2 { println!("c1 == c2"); } else { println!("c1 != c2"); } }
エラー例
2字以上入れる
error: character literal may only contain one codepoint --> main.rs:8:14 | 8 | let c3 = 'AB'; | ^^^^
ダブルクォート
error[E0308]: mismatched types --> main.rs:9:20 | 9 | let c4: char = "A"; | ^^^ expected char, found reference | = note: expected type `char` found type `&'static str`
Rustはクォートの種類によって型が変わるらしい。
クォート | 型 |
---|---|
シングル' |
char |
ダブル" |
&'static str |
参考
対象環境
- Raspbierry pi 3 Model B+
- Raspbian stretch 9.0 2018-11-13
- bash 4.4.12(1)-release
$ uname -a Linux raspberrypi 4.19.42-v7+ #1219 SMP Tue May 14 21:20:58 BST 2019 armv7l GNU/Linux
前回まで
- Rustを学んでみたい(プログラミング言語)
- Rustの環境構築
- RustでHelloWorld
- Rustの和訳ドキュメント
- Cargoでプロジェクト作成・ビルド・実行
- クレートとは?
- Rustで関数を使ってみる
- Rustでモジュールを使ってみる
- Rustで乱数を生成する(rand)
- Rustで標準入力する(std::io::stdin().read_line())
- RustでMatch判定する(match)
- Rustでprintとread_lineを1行にする方法
- Rustで数当てゲーム
- クレート名にドット.が使えない
- Rustの変数と可変性(let, mut) error[E0384]: cannot assign twice to immutable variable
x
- Rustのimmutable束縛とconst定数の違い
- RustのREPL、evcxrのインストールに失敗した
- Rustでコンパイルするときの変数未使用warningを消す
- Rustの変数(再代入、再宣言(シャドーイング))
- Rustのシャドーイングについて
- イミュータブルについて(副作用)
- Rustの定数(const)
- Rustのデータ型(数値)
- Rustのデータ型(論理)