dtolnay/cxx

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

開放

#290 建立於 2020年9月9日

 (1 則留言) (0 個反應) (0 位負責人)Rust (253 個分叉)batch import
help wantedneeds design

倉庫指標

星標
 (4,472 顆星)
PR 合併指標
 (PR 指標待抓取)

描述

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

貢獻者指南