LoginSignup
0
0

Rust で AtCoder やるときのフォルダ構成決まった

Posted at

前提

  • 基本的に ABC しかやっていない
  • ABC 以外の問題が出たときに同じような構成で楽がしたい

Tree

  • 358 以外にもあるがでかいので割愛
.
├── ABC
│   └── 358
│       ├── Cargo.toml
│       └── src
│           ├── a.rs
│           ├── b.rs
│           ├── c.rs
│           ├── d.rs
│           ├── e.rs
│           ├── ex.rs
│           ├── f.rs
│           └── g.rs
├── Cargo.lock
├── Cargo.toml
change_abc_target.sh
└── abc_prepare.sh

abc_prepare.sh の中身

if [ -z "${1}" ]; then
    echo "You should set contest number"
    exit 1
fi
mkdir -p ABC/$1
mkdir -p ABC/$1/src
touch ABC/$1/Cargo.toml
echo "[package]
name = \"abc_$1\"
version = \"0.1.0\"
authors = [\"root\"]
edition = \"2018\"

[dependencies]
proconio = \"0.4.5\"
itertools = \"0.10.5\"
ac-library-rs = \"0.1.1\"" > ABC/$1/Cargo.toml

alphabet=(A B C D E F G Ex)
for abc in ${alphabet[@]}; do
    lower_case=$(echo $abc | tr 'A-Z' 'a-z')
    touch ABC/$1/src/$lower_case.rs

    echo "
[[bin]]
name = \"$lower_case\"
path = \"src/$lower_case.rs\"" >> ABC/$1/Cargo.toml

    echo "use proconio::input;

fn main(){
    input!{

    };
}" > ABC/$1/src/$lower_case.rs
done

echo "[workspace]
members = [
    \"ABC/$1\",
    \"ironclad_rule\"
]" > Cargo.toml;

ルートの Cargo.toml の中身

[workspace]
members = [
    "ABC/358",
    "ironclad_rule"
]
  • ironclad_rule については鉄則本を進めていく中でいちいちルートの Cargo.toml が変更されるのが嫌だったためここだけ指定
  • ABC/358 で番号を指定している理由は不要に rust-analyzer が動かないでほしかったため

change_abc_target.sh の中身

if [ -z "${1}" ]; then
    echo "You should set contest number"
    exit 1
fi

echo "[workspace]
members = [
    \"ABC/$1\",
    \"ironclad_rule\"
]

resolver = \"2\"" > Cargo.toml;
  • target の ABC の番号だけ変えるためにつかってる

コンテスト参加時に以下を実行

bash abc_prepare.sh 358(コンテストの番号)
  • ここでその回のコンテストの a ~ g の .rs を作成して proconio::input を書き込む

実行時

  • 該当のコンテストナンバーに移動
  • それぞれの問題のファイルを指定して実行
cd ABC/358
cargo run --bin a

TODO

  • テストいい感じに書けるようにしてぇ~
0
0
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
0
0