dtolnay/cxx

Preserve cause-chain of errors propagated from rust -> c++ -> rust

Open

#290 创建于 2020年9月9日

在 GitHub 查看
 (1 评论) (0 反应) (0 负责人)Rust (4,472 star) (253 fork)batch import
help wantedneeds design

描述

use anyhow::{anyhow, Result};

#[cxx::bridge]
mod ffi {
    extern "C" {
        include!("repro.h");
        fn cthing() -> Result<()>;
    }

    extern "Rust" {
        fn rustthing() -> Result<()>;
    }
}

fn rustthing() -> Result<()> {
    Err(anyhow!("no such file or directory").context("failed to open: /nonexist"))
}

fn main() -> Result<()> {
    ffi::cthing()?;
    Ok(())
}
// repro.cc

void cthing() {
  rustthing();
}

This currently loses the cause chain and only prints:

Error: failed to open: /nonexist

贡献者指南