最初にやるのはcargo newである。
> cargo new money Created binary (application) `money` package > cd money > ls -la total 16 drwxr-xr-x 6 tambara staff 192 3 20 17:48 . drwxr-xr-x 3 tambara staff 96 3 20 17:48 .. drwxr-xr-x 8 tambara staff 256 3 20 17:48 .git -rw-r--r-- 1 tambara staff 8 3 20 17:48 .gitignore -rw-r--r-- 1 tambara staff 226 3 20 17:48 Cargo.toml drwxr-xr-x 3 tambara staff 96 3 20 17:48 src
.gitまで出来ちゃう辺りが新世代って感じ。
さて、まずは実行してみますか。
> cargo run Compiling money v0.1.0 (/Users/tambara/study/tdd_rust/money) Finished dev [unoptimized + debuginfo] target(s) in 0.34s Running `/Users/tambara/study/tdd_rust/money/target/debug/money` Hello, world!
Hello, worldが書かれていたようだ(笑)。
さて、もちろんVimでコードを書いていってもいいわけだけど、 今回はVScodeも使ってみたい。 私は本当に手に馴染んだIDEというものがないのだ。
このファイルがRustのソースコードであることは知っているわけだ。
ただし、このレベルではVimと大差ない。 Rustは公式のLanguage Serverがあるらしいので、もっと格好良くなるはず。
というわけで、拡張を入れる事にする。 拡張をクリックすると、RECOMMENDEDのトップにRust(rls)が出ている。 入れるべきなのはこれなんだけど、「お前、Rust書くのか。・・・入れるだろ」と 見透かされているようでなんかムカつく(笑)。
ま、入れますけど。
入れると、「rls入ってへんがな」と怒られる。
https://github.com/rust-lang/rls
を見て、インストールする。
> rustup update info: syncing channel updates for 'stable-x86_64-apple-darwin' info: checking for self-updates stable-x86_64-apple-darwin unchanged - rustc 1.42.0 (b8cedc004 2020-03-09) info: cleaning up downloads & tmp directories > rustup component add rls rust-analysis rust-src info: downloading component 'rls' info: installing component 'rls' info: downloading component 'rust-analysis' info: installing component 'rust-analysis' info: downloading component 'rust-src' info: installing component 'rust-src'
これでいいのかな?
ステータスバーのRLSのところがRLS:starting
のままになって
動かない状態になって上手く動かなかったんだけど、
その後、最新版へのUPDATE指示が出て、更新して再起動したら動いた。なんか謎。
サジェスチョンでるようになった。おおー。