MENU
やすひら
やすひらと申します。
長靴を履いたタヌキ(ITエンジニア)です。
モノ作りの楽しさを発信中。
X(旧Twitter)のフォローもお願いします。

[初心者向け]Rustとは

Rustは、メモリ安全性が高く、処理速度が早い、コンパイル型のプログラミング言語です。
本記事では、Rustの概要と特徴について紹介します。

やすひら

Rustの概要と特徴を紹介します

この記事でわかること
  • Rustの概要
  • Rustの特徴
  • Rustでできること
目次

Rustとは

Rustは、コンパイル型のプログラミング言語です。
Cargoにより、ビルドと依存管理を行います。
メモリの安全性を、コンパイル時に検出するため、メモリ破壊が起きにくい設計となっています。
Rustのコンパイラは、非常に厳しいですが、コンパイルを通すことができれば、安全にプログラムを実行することができます。
所有権/借用/ライフタイムという、Rust固有の考え方があります。
他のプログラミング言語と比較して、速度が早いことも特徴の一つです。
Rustはオープンソースなので、無料で利用できます。

Rustの特徴

Rustの特徴を紹介します。

所有権によるメモリ管理

Rustは、不要なメモリ領域を自動で解放する、ガーベージコレクション(GC)はありませんが、所有権によって管理します。

所有権

すべての値には、所有者(owner)を持つ必要があります。
所有者は常に1つで管理します。
所有者がスコープを抜けると、値は自動的に破棄されます。

ムーブ

代入や関数の引き渡しにより、所有者を移動することができます。
値を変数に代入すると、Rustでは代入先に所有権が移動します。
所有権が移動することにより、代入元の値は使用不可となります。
これにより、2つの変数が同じメモリを参照したり、両方が二重解放することを防止します。

借用

所有権を移動せずに、借用することもできます。

  • 不変の借用(&):同時に何個も利用できる
  • 可変の借用(&mut):同時に1つ利用できる。不変の借用と共存不可。

不変の借用は参照に利用する。
可変の借用は更新に利用する。

データ競合の定義を、コンパイル時に禁止することで、マルチスレッドによるデータ競合のバグを防止しています。

ライフタイム

参照が有効な期間を設定することができます。
通常はコンパイラが自動で設定しますが、明示的に定義することができます。

null定義不可

Rustにはnullは存在しません。
値があるかもしれないという変数は、Option型で定義し、値がない場合の処理を書かないとコンパイルエラーとなります。
nullポインター参照によるクラッシュを防止するための仕組みです。

例外なし

Rustでは、例外処理は存在しません。
エラーは、Result型で返却し、エラーを無視した場合は、コンパイラが警告します。

厳しいコンパイル

Rustでは、コンパイル時のチェックを厳しくすることで、データや処理の安全性を担保しています。
実行してみなければエラーとなるかわからないような事象を、コンパイル時に検出できるのがメリットの1つです。

ゼロコスト抽象化

高水準な書き方をしても、コンパイル後は機械語になります。
一般的に抽象化すると処理速度が遅くなりますが、Rustの場合はコンパイルにより機械語になることで、処理速度は遅くなりません。

統合ツール(Cargo)

Rustでは、Cargoという統合ツールで、様々な作業ができます。

  • ビルド
  • 依存管理
  • テスト
  • ドキュメント整理
  • フォーマット

cargoコマンド1つで、開発ができます。

Rustのインストール

Rustのインストール方法を紹介します。

Rustはaptでもインストールできますが、古いバージョンの場合があるため、以下の手順でインストールします。

関連パッケージのインストール

関連パッケージをインストールします。

コマンドライン

sudo apt update
sudo apt install -y curl build-essential

コマンド実行例

$ sudo apt update
[sudo] password for user: 
Get:1 https://cli.github.com/packages stable InRelease [3917 B]
Get:2 https://download.docker.com/linux/ubuntu jammy InRelease [48.5 kB]       
Hit:3 http://ports.ubuntu.com jammy InRelease                                  
Hit:4 http://ports.ubuntu.com jammy-updates InRelease
Hit:5 http://ports.ubuntu.com jammy-security InRelease
Hit:6 http://ports.ubuntu.com jammy-backports InRelease
Fetched 52.4 kB in 3s (17.8 kB/s)
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
60 packages can be upgraded. Run 'apt list --upgradable' to see them.
$ sudo apt install -y curl build-essential
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
build-essential is already the newest version (12.9ubuntu3).
curl is already the newest version (7.81.0-1ubuntu1.25).
0 upgraded, 0 newly installed, 0 to remove and 60 not upgraded.

curlとbuild-essentialをインストールします。

Rustのインストール

Rustをインストールします。

コマンドライン

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

コマンド実行例

$ curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
info: downloading installer
warn: It looks like you have an existing rustup settings file at:
warn: /home/user/.rustup/settings.toml
warn: Rustup will install the default toolchain as specified in the settings file,
warn: instead of the one inferred from the default host triple.

Welcome to Rust!

This will download and install the official compiler for the Rust
programming language, and its package manager, Cargo.

Rustup metadata and toolchains will be installed into the Rustup
home directory, located at:

  /home/user/.rustup

This can be modified with the RUSTUP_HOME environment variable.

The Cargo home directory is located at:

  /home/user/.cargo

This can be modified with the CARGO_HOME environment variable.

The cargo, rustc, rustup and other commands will be added to
Cargo's bin directory, located at:

  /home/user/.cargo/bin

This path will then be added to your PATH environment variable by
modifying the profile files located at:

  /home/user/.profile
  /home/user/.bashrc

You can uninstall at any time with rustup self uninstall and
these changes will be reverted.

Current installation options:


   default host triple: aarch64-unknown-linux-gnu
     default toolchain: stable (default)
               profile: default
  modify PATH variable: yes

1) Proceed with standard installation (default - just press enter)
2) Customize installation
3) Cancel installation
>

info: profile set to default
info: default host triple is aarch64-unknown-linux-gnu
info: syncing channel updates for stable-aarch64-unknown-linux-gnu
info: latest update on 2026-07-16 for version 1.97.1 (8bab26f4f 2026-07-14)
info: downloading 6 components
        cargo installed                       10.09 MiB
       clippy installed                        3.75 MiB
    rust-docs installed                       22.74 MiB
     rust-std installed                       28.85 MiB
        rustc installed                       59.83 MiB
      rustfmt installed                        1.87 MiB                         info: default toolchain set to stable-aarch64-unknown-linux-gnu

  stable-aarch64-unknown-linux-gnu installed - rustc 1.97.1 (8bab26f4f 2026-07-14)


Rust is installed now. Great!

To get started you may need to restart your current shell.
This would reload your PATH environment variable to include
Cargo's bin directory ($HOME/.cargo/bin).

To configure your current shell, you need to source
the corresponding env file under $HOME/.cargo.

This is usually done by running one of the following (note the leading DOT):
. "$HOME/.cargo/env"            # For sh/bash/zsh/ash/dash/pdksh
source "$HOME/.cargo/env.fish"  # For fish
source "~/.cargo/env.nu"  # For nushell
source "$HOME/.cargo/env.tcsh"  # For tcsh
. "$HOME/.cargo/env.ps1"        # For pwsh
source "$HOME/.cargo/env.xsh"   # For xonsh

Rustをインストールします。

パスを通す

パスを通します。

コマンドライン

. "$HOME/.cargo/env"

コマンド実行例

$ . "$HOME/.cargo/env"

パスを通します。

Rustのインストールを確認

Rustのインストールを確認します。

コマンドライン

rustc --version
cargo --version

コマンド実行例

$ rustc --version
rustc 1.97.1 (8bab26f4f 2026-07-14)
$ cargo --version
cargo 1.97.1 (c980f4866 2026-06-30)

Rustのインストールを確認します。
rustcとcargoのバージョンが出力されれば、インストールが完了しています。

まとめ

Rustの概要と特徴を紹介しました。

Rustは
  • コンパイル型のプログラミング言語
  • 所有権という概念がある
  • バグを起こさない仕組みとしてコンパイル条件が厳しい
  • Cargoという統合ツールで開発できる
  • 処理速度が早い

Rustは、コンパイル型で高速に処理ができるプログラミング言語です。
コンパイルのチェック条件の厳しさや、所有権の概念は、学習コストがかかりますが、安全な実行ファイルを作成できるため、メリットは大きいです。
Rustを学んで、高度なプログラミングができるエンジニアになりましょう。

  • URLをコピーしました!
目次