snafu

Easily assign underlying errors into domain-specific errors while adding context

  • 所有者: shepmaster/snafu
  • 平台:
  • 许可证: Apache License 2.0
  • 分类:
  • 主题:
  • 喜欢:
    0
      比较:

Github星跟踪图

SNAFU

Situation Normal: All Fouled Up

crates.io
Documentation
Build Status

SNAFU is a library to easily assign underlying errors into
domain-specific errors while adding context.

use snafu::{ResultExt, Snafu};
use std::{fs, io, path::PathBuf};

#[derive(Debug, Snafu)]
enum Error {
    #[snafu(display("Unable to read configuration from {}: {}", path.display(), source))]
    ReadConfiguration { source: io::Error, path: PathBuf },

    #[snafu(display("Unable to write result to {}: {}", path.display(), source))]
    WriteResult { source: io::Error, path: PathBuf },
}

type Result<T, E = Error> = std::result::Result<T, E>;

fn process_data() -> Result<()> {
    let path = "config.toml";
    let configuration = fs::read_to_string(path).context(ReadConfiguration { path })?;
    let path = unpack_config(&configuration);
    fs::write(&path, b"My complex calculation").context(WriteResult { path })?;
    Ok(())
}

fn unpack_config(data: &str) -> &str {
    "/some/path/that/does/not/exist"
}

Please see the documentation and the user's guide for
a full description.

主要指标

概览
名称与所有者shepmaster/snafu
主编程语言Rust
编程语言Rust (语言数: 2)
平台
许可证Apache License 2.0
所有者活动
创建于2019-01-27 15:56:35
推送于2024-11-19 17:21:04
最后一次提交
发布数48
最新版本名称0.8.5 (发布于 )
第一版名称0.1.0 (发布于 )
用户参与
星数1.6k
关注者数17
派生数62
提交数724
已启用问题?
问题数223
打开的问题数79
拉请求数219
打开的拉请求数6
关闭的拉请求数15
项目设置
已启用Wiki?
已存档?
是复刻?
已锁定?
是镜像?
是私有?