削除された内容 追加された内容
Ef3 (トーク | 投稿記録)
タグ: 2017年版ソースエディター
Ef3 (トーク | 投稿記録)
タグ: 2017年版ソースエディター
46 行
}
</syntaxhighlight>
 
== 変数と型 ==
Rustは、静的な型システムを採用しています。
;[https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021 variables-types.rs]:<syntaxhighlight lang=rust>
fn main() {
let x = 999;
print!("{}({}), ", x, type_of(x));
let x = -123;
print!("{}({}), ", x, type_of(x));
let x = 999u32;
print!("{}({}), ", x, type_of(x));
let x = -123i32;
print!("{}({}), ", x, type_of(x));
let x = 999u64;
print!("{}({}), ", x, type_of(x));
let x = -123i64;
print!("{}({}), ", x, type_of(x));
let x = 1.0;
print!("{}({}), ", x, type_of(x));
let x = 3.14f32;
print!("{}({}), ", x, type_of(x));
println!();
let x = "abc";
print!("{}({}), ", x, type_of(x));
let x = true;
print!("{:?}({}), ", x, type_of(x));
let x = [1, 2, 3];
print!("{:?}({}), ", x, type_of(x));
let x = (1, 2, 3);
print!("{:?}({}), ", x, type_of(x));
let x = &vec![10, 20, 30];
print!("{:?}({}), ", x, type_of(x));
}
 
fn type_of<T>(_: T) -> &'static str {
std::any::type_name::<T>()
}
</syntaxhighlight>
;実行結果:<syntaxhighlight lang=text>
</syntaxhighlight>
 
=== 変数・定数とミュータブル・イミュータブル ===
変数を宣言するにはletを使いますが、Rustではイミュータブル(''Immutable'';作成後には変更不能)なオブジェクトとして作成されます。
ミュータブル(''Mutable'';作成後にも変更可能)なオブジェクトを宣言するには、'''mut''' を使います。
 
=== 識別子 ===
 
=== スコープ ===
 
== 制御構造 ==
Rust では、{{code|if}}や{{code|for}}などの制御構造も式です。
 
== 脚註 ==