Rust 基礎

👻 インストール(mac)

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

公式のままだと「error: could not amend shell profile: '/Users/akaishishingo/.bash_profile': could not write rcfile file: '/Users/akaishishingo/.bash_profile': Permission denied (os error 13)」とエラーになる。

よって「s -- --no-modify-path」を末尾に追加している。

無事にインストールが完了すると

To configure your current shell, run:
source "$HOME/.cargo/env"

とメッセージが出るので

$HOME/.cargo/env

を実行。

すると、「zsh: permission denied: /Users/akaishishingo/.cargo/env」(zsh: 許可が拒否されました:)とエラーを出されるので、ファイル許可を確認。

cd $HOME/.cargo
ls -l

# >>>
drwxr-xr-x  16 akaishishingo  staff  512  5  3 17:04 bin
-rw-r--r--   1 akaishishingo  staff  300  5  3 17:04 env
# >>>

と.envがrwしかない(rwxrじゃない)のが確認できたので、.envの権限を変更。

chmod 755 env

これで再度

$HOME/.cargo/env

を実行すると無事通った。

次に、パスを通したままにしたいので

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

を実行。エラーが出なければ、インストールまでは完了。

👾 実行テスト

実行コマンド[cargo]のテスト。

cargo --version

# >>>
cargo 1.69.0 (6e9a83356 2023-04-12)
# >>>

のようにバージョンが出れば無事インストール完了。

※cargoは、Rustのコンパイルマネージャー兼パッケージマネージャー。

👨🏻‍💻 開発環境

以下で、新しい開発環境をセット。

cargo new 開発環境ディレクトリ

開発環境へ幾つかのファイルが自動生成される。

src/main.rs を実行してみる。

以下のコマンドで、コンパイルと実行を合わせて行うことができる。

cargo run

(続きは以下も参照する)

https://www.rust-lang.org/ja/learn

史上最強のデータベース、SurrealDB

https://qiita.com/silane1001/items/795c3539675e588c2c4d

https://surrealdb.com/install

Rust on AWS

https://aws.amazon.com/jp/developer/language/rust/

Rust による持続可能性

https://aws.amazon.com/jp/blogs/opensource/sustainability-with-rust/?pg=devrust