dtolnay/cxx
Preserve cause-chain of errors propagated from rust -> c++ -> rust
オープン
#290 opened on 2020/09/09
help wantedneeds design
Repository metrics
- Stars
- (4,472 個のスター)
- PR merge metrics
- (平均マージ 8m) (30d で 3 merged PRs)
説明
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