7
6

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 5 years have passed since last update.

RUST ironフレームワーク入門

7
Last updated at Posted at 2017-07-01

Mozillaが中心となってオープンソースで開発されている言語「Rust」。
Mozillaが開発を主導しているためか、WebAssembly対応に非常に積極的です。
今回はRustをインストールし、ironフレームワークから「Hello World」を出すところまで。 Rustのビルドシステム兼パッケージマネージャのCargoを使用します。

rust install

cd ~/ に移動し以下を実行します。
curl https://sh.rustup.rs -sSf | sh

実行すると以下の文言がでてくるので、1を選択。

1) Proceed with installation (default)
2) Customize installation
3) Cancel installation

成功すると以下のように表示されるはずです
Rust is installed now. Great!

cargo

RustのビルドシステムであるCargoを使います。
またパッケージマネージャでありCargoをRustプロジェクトの管理にも使用します。
公式インストーラーからrustを導入しているなら、rustに同梱されているはずです。
cargo --version
もし出ない場合はpathを通す必要があるので、~/.bashrcに追記します。

# Rust 
export PATH="$HOME/.cargo/bin:$PATH" 

追記後パスを反映させる source ~/.bashrcを実行します。

ironフレームワークにてプロジェクトを作成

任意のディレクトリにて以下を実行
cargo new iron
ironプロジェクトを作成します。

実行するとCargo.toml ファイルと srcのディレクトリができていると思います。

Cargo.tomlに以下を追記します。

[dependencies.iron]
version = "*"

srcディレクトリに新しくmain.rsファイルを作成し以下を記述します。

extern crate iron;

use iron::prelude::*;
use iron::status;

fn main() {
    Iron::new(|_: &mut Request| {
        Ok(Response::with((status::Ok, "Hello world!")))
    }).http("localhost:3000").unwrap();
} 

cargo buildを実行しビルドします。
最後に以下にてプログラムを実行できます。
cargo run

http://localhost:3000/
にてHello world!が確認できれば成功です。

7
6
0

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
7
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?