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