LoginSignup
15
5

More than 3 years have passed since last update.

RustのFerrisもかわいいけどClippyもかわいいぞ

Last updated at Posted at 2020-12-25

この記事は「イエソド アウトプット筋 トレーニング Advent Calendar 2020」23日目の記事です。

ferris vs clippy

公式マスコットキャラクターの蟹のFerrisくん。かわいいですね。
数ある言語のマスコットキャラの中で1番好きかもしれません。

rustacean-orig-noshadow.png

チュートリアルでも、このマスコットキャラクターを使ってかわいく標準出力するライブラリferris-saysが紹介されています。
こんな子がチヤホヤされている裏でライブラリに用意されているのに使用されることのないキャラクター?を見つけてしまったので、今回はそのご紹介。

環境

  • MacOS Catalina 10.15.7
  • Rust v1.48.0
  • IntelliJ Ultimate 2020.3
$ rustup -V

rustup 1.23.1 (3df2264a9 2020-11-30)
info: This is the version for the rustup toolchain manager, not the rustc compiler.
info: The currently active `rustc` version is `rustc 1.48.0 (7eac88abb 2020-11-16)`

Rust自体のインストール手順はこちら
(Windowsの人はdocumentにもある通り、こちらを参照)

実装

まずはチュートリアル通りにプロジェクトを作成します。

$ rustup new hello-rust

    Created binary (application) `hello-rust` package

何らかのIDE(今回はIntelliJ)で開きます。

cargo.tomlに依存を追加します。

cargo.toml
[package]
name = "hello-rust"
version = "0.1.0"
authors = ["swalowtail62 <example@example.com>"]
edition = "2018"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
ferris-says = "0.2" # 追加

main.rsも修正します。

main.rs
use ferris_says::say;
use std::io::{stdout, BufWriter};

fn main() {
    let stdout = stdout();
    let message = String::from("Hello fellow Rustaceans!");
    let width = message.chars().count();

    let mut writer = BufWriter::new(stdout.lock());
    say(message.as_bytes(), width, &mut writer).unwrap();
}

これを実行すると、

$ cargo run src/main.rs

 __________________________
< Hello fellow Rustaceans! >
 --------------------------
        \
         \
            _~^~^~_
        \) /  o o  \ (/
          '_   -   _'
          / '-----' \

ちゃんととてもかわいらしいferrisくんが喋っています。

とてもとてもかわいすぎて内部実装が気になったのでGitHUbを調べてみると、別のキャラクターがいるではありませんか!
チュートリアルでもferrisくんが登場するだけで、日の目を浴びることのないこの子。。使ってあげないとあまりにかわいそうです。

ferrisの代わりに彼を使うには、Rustのfeaturesを利用すればOKです。早速やってみましょう。

cargo.toml

[dependencies]
- ferris-says = "0.2"
+ ferris-says = { version = "0.2", features=["clippy"] }

先ほどの該当ソースコードを読めばわかりますが、ferris-saysライブラリのfeaturescargo.tomlに記載されています。

これで再度実行してみると、

$ cargo run src/main.rs

 __________________________
< Hello fellow Rustaceans! >
 --------------------------
        \
         \
            __
           /  \
           |  |
           @  @
           |  |
           || |/
           || ||
           |\_/|
           \___/

。。。あまりかわいくはありませんね。
やっぱり王道のferrisくんしか勝たんですね。


↑のが正式にclippyという名前のキャラクターなのかは分かりません。勝手に呼んでいます。
Rustでclippyというと、lintライブラリが連想されると思います。果たしてこのライブラリのキャラクターということなのか、、?

15
5
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
15
5