| Crates.io | rust_hero |
| lib.rs | rust_hero |
| version | 0.5.2 |
| created_at | 2022-10-13 06:45:53.9922+00 |
| updated_at | 2022-10-31 03:48:51.42447+00 |
| description | Rust assistant that utilizes NLP to enhance the quality of rust code. |
| homepage | |
| repository | https://github.com/yijunyu/curs |
| max_upload_size | |
| id | 687006 |
| size | 194,445 |
rust_hero is a rust assistant that utilizes NLP to enhance the quality of rust code. It supports unsafe and lifetime (todo) prediction.
[dependencies]
rust_hero = "0.5"
For each function in Rust, the unsafe keyword utilizes the unsafe superpowers. However, the unsafe keyword is not necessary if it can be taken out while the program is compiled successfully.
rust_hero infers the necessity of unsafe keywords without the need of recompiling. rust_hero trains a microsoft/codebert based model and take advantage of bert's strong reasoning capability to inference the necessity of unsafe.
Implementation of the language query in this project is based on BrianHicks/tree-grepper.
It costs 2.06s and 2.90s on average for rust_hero inferencing one rust file on Intel I7-12700K CPU and NVIDIA 3080 12GB GPU, seperately.
rust_hero written in Rust achieves up to 6.58X and 13.04X performance speedup over rust_hero written in Python language for GPU and CPU, seperately.

sudo apt install build-essential cmake pkg-config libssl-dev wget zip git
Download the tree-grepper vendor (cargo build also download the vendor automatically):
bash ./scripts/runtime.sh
It uses libtorch-1.12.0 (See rust-bert) to inference rust_hero. Download the libtorch with CPU or CUDA from following links:
CPU: https://download.pytorch.org/libtorch/cpu/libtorch-cxx11-abi-shared-with-deps-1.12.0%2Bcpu.zip
CUDA: https://download.pytorch.org/libtorch/cu116/libtorch-cxx11-abi-shared-with-deps-1.12.0%2Bcu116.zip
Unzip the file and set the environment path in .bashrc:
export LIBTORCH=$libtorchDir$/libtorch
export LD_LIBRARY_PATH=${LIBTORCH}/lib:$LD_LIBRARY_PATH
source .bashrc
or in 'envConfig' of work directory:
export LIBTORCH=$libtorchDir$/libtorch
export LD_LIBRARY_PATH=${LIBTORCH}/lib:$LD_LIBRARY_PATH
source envConfig
50 rust files for testing is elaboratly selected from open-source rust project including on rust-openssl, tokio, anyhow, hyper, rand, regex and rayon:
bash ./scripts/prepare_data.sh
cargo run data/error.rs
rust_hero also supports classifling all rust files of one directory:
cargo run data/