Crates¶
Crates¶
クレートはRustプログラムのパッケージを表す。
cargo new するとcrateが作られる。
https://crates.io/ はクレートの公開レジストリ。 自作のクレートをここに登録することでユーザーに配布することができる。
参考:
clap¶
人気のCLIライブラリ。
exitfailure¶
https://crates.io/crates/exitfailure
Some newtype wrappers to help with using ? in main()
NOTE:
- 下のfailureと合わせて参考に挙げたガイドで紹介されているが、2020-05-30現在、2018-08-03で更新が止まっている。それだけ枯れてるのならいいのかもしれないが。
参考:
failure¶
An experimental new error-handling library.
ガイド:
参考:
Context¶
An error with context around it.
ResultExt¶
Extension methods for Result.
with_context¶
https://docs.rs/failure/0.1.8/failure/trait.ResultExt.html#tymethod.with_context
fn with_context<F, D>(self, f: F) -> Result<T, Context<D>>
// F: FnOnce(&E) -> D,
// D: Display + Send + Sync + 'static,
Wraps the error type in a context type generated by looking at the error value.
Examples:
#[derive(Fail, Debug)]
#[fail(display = "My custom error message")]
struct CustomError;
let x = (|| -> Result<(), failure::Error> {
Err(CustomError)?
})().with_context(|e| {
format!("An error occured: {}", e)
}).unwrap_err();
let x = format!("{}", x);
assert_eq!(x, "An error occured: My custom error message");
rand¶
乱数生成
structopt¶
https://crates.io/crates/structopt
clapに依存したCLIライブラリ。
structを定義することでコマンドライン引数を解析する。