rust_hero 0.5.2

Rust assistant that utilizes NLP to enhance the quality of rust code.
//! # Additional toolings for rust
//! rust_hero is a rust assistant that utilizes NLP to program rust more efficiently. It supports `unsafe` and `lifetime` (todo) prediction.
//! # `unsafe` prediction
//! 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](https://github.com/microsoft/CodeBERT) based model and take advantage of bert's strong reasoning capability to inference the necessity of `unsafe`.
//!
//! # `lifetime` prediction
//! todo
//!
//! # Usage
//!
//! ```no_run
//!
//! use anyhow::{Context, Result};
//! use rust_hero::query::{Invocation, QueryFormat};
//! use rust_hero::safe::{show_languages, SafeLanguageModel};
//! use std::env;
//! use std::io::{self, BufWriter, Write};
//!
//! pub fn main() {
//!     let mut buffer = BufWriter::new(io::stdout());
//!
//!     if let Err(error) = try_main(env::args().collect(), &mut buffer) {
//!         if let Some(err) = error.downcast_ref::<io::Error>() {
//!             // a broken pipe is totally normal and fine. It's what we get when
//!             // we pipe to something like `head` that only takes a certain number
//!             // of lines.
//!             if err.kind() == io::ErrorKind::BrokenPipe {
//!                 std::process::exit(0);
//!             }
//!         }
//!
//!         if let Some(clap_error) = error.downcast_ref::<clap::Error>() {
//!             // Clap errors (--help or misuse) are already well-formatted,
//!             // so we don't have to do any additional work.
//!             eprint!("{}", clap_error);
//!         } else {
//!             eprintln!("{:?}", error);
//!         }
//!
//!         std::process::exit(1);
//!     }
//!
//!     buffer.flush().expect("failed to flush buffer!");
//! }
//!
//! pub fn try_main(args: Vec<String>, out: impl Write) -> Result<()> {
//!     let invocation = Invocation::from_args(args)
//!         .context("couldn't get a valid configuration from the command-line options")?;
//!     match invocation {
//!         Invocation::DoQuery(query_opts) => {
//!             let safe_model = SafeLanguageModel::new(query_opts)?;
//!             match safe_model.get_opt().format {
//!                 QueryFormat::Classes => {
//!                     let output = safe_model
//!                         .predict()
//!                         .context("couldn't perform the prediction")?;
//!                     for label in output {
//!                         println!("{:?}", label);
//!                     }
//!                     Ok(())
//!                 }
//!                 _ => safe_model.do_query(out),
//!             }
//!         }
//!         Invocation::ShowLanguages => {
//!             show_languages(out).context("couldn't show the list of languages")
//!         }
//!     }
//! }
//! ```
//!
pub mod query;
pub mod safe;