高木のブログ

RustでHello, World!

· 84 words · 1 minutes to read
Tags: Rust Docker

Rustも触っておきたいなと思ったので、取り急ぎのHello, World!をやってみた。

手順 🔗

事前準備 🔗

RustのDockerイメージを取得し、コンテナに入る 🔗

$ docker pull rust:1.48.0
$ docker run -it --rm rust:1.48.0 bash
root@6819088df44e:/#

Vimのインストール 🔗

root@6819088df44e:/# apt update
root@6819088df44e:/# apt install -y vim

作業用ディレクトリを作成し、移動 🔗

root@6819088df44e:/# mkdir hello_world
root@6819088df44e:/# cd hello_world
root@6819088df44e:/hello_world#

Rustファイル作成 🔗

root@6819088df44e:/hello_world# vim main.rs
fn main() {
    println!("Hello, World!");
}

コンパイル 🔗

root@6819088df44e:/hello_world# rustc main.rs
root@6819088df44e:/hello_world# ls
total 3136
-rwxr-xr-x 1 root root 3205040 Dec 30 12:41 main
-rw-r--r-- 1 root root      45 Dec 30 12:40 main.rs

mainという名前の実行可能ファイルができている。

実行 🔗

root@6819088df44e:/hello_world# ./main
Hello, world!

参考 🔗

Hello, World! - The Rust Programming Language

Categories


Tags