###### tags: `Rust` `Udemy` # Rust Udemy Course youtubeの動画で拾いそこねたところだけ # 準備 開発環境 IntelliJ IDEA Rustプロジェクトを作成する Toml プラグインを入れて Cargo.toml をハイライトできるようにする # section2. Types and Valiables ## i8/16/32/64 , f32/64 ## type function `i32::powi(a, b)` : aをb乗する `f64::powf(c, d)` : cをd乗する(小数可) ## bit演算 `1 | 2` : or | : or ^ : xor & : and ## スコープ {} 関数の中に {} を書いてスコープを作ることができる。 スコープ内で既にある変数名を使うと、上書きされる。 ```rust= fn main(){ { let a = 16; println!("{}", a); } } ``` ## Stack と Heap ### Stackを使う場合 普通に変数を定義した場合 ```rust= let x = 5; let y = 32; ``` ### Heapを使う場合 **Box::new(\<T>)** を使う場合 T は ジェネリックタイプ ```rust= let x = Box::new(5); let y = Box::new("hello"); ``` ## Box構造体 Heap領域に割り当てられたポインター型 領域はHeapに割り当てられる ポインター変数はStackに割り当てられる。 ポインターなので、使うときは * アスタリスクを使う ```rust= println!("{}", *x); ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up