lovasoa / custom_error

Define custom errors without boilerplate using the custom_error! macro.

Home Page:https://crates.io/crates/custom_error

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add #[repr(C)] for enums

adamski opened this issue · comments

I'm writing a Rust library that exposes a C API. We are defining a custom error type using this library (thank you!). I would like to be able to expose the enum to the C API, and have it be picked up by cbindgen. Looking at the syntax for adding e.g. #[derive(PartialEq)] I tried adding #[repr(C)] but it does not work as I hoped!

E.g.

custom_error!{
    #[repr(C)]
    MyError
        A="error a",
        B="error b"
}

I assume there are two issues here:

  1. Support #[repr(C)] for enums/structs (which may already be the case?)
  2. Allow cbindgen to pick it up. I believe) cbindgen scans the source, and I'm not sure if it sees expanded macros or not.

Hello! custom_error already supports annotations. What more can it do?

I am going to close this since this is not actionable. repr(C) is already supported (just like any other annotation). If cbindgen wants to add support for parsing macro calls, they can; but there is nothing we can do inside this library. You may want to use another error handling library that is not based on macro calls.