2021-07-11から1日間の記事一覧

anyhowを使ってエラーの型に応じた処理を書く

rustのanyhowを使って、エラーの型に応じた処理を書く方法が分からなかったのでメモ。 以下の★のところで処理を記述している。 use anyhow::{Context, Result}; fn get_int() -> Result<i32> { let path = "test.txt"; let num_s = std::fs::read_to_string(path)</i32>…