Use Result
with stable size, alignment, and ABI guarantees ?
#1035
Labels
Result
with stable size, alignment, and ABI guarantees ?
#1035
👋 Hi folks,
Since RFC 3391 (rust-lang/rfcs#3391) the
Result
type's documentation has a Representation section that describes conditions whereResult<T, E>
can have the same size, alignment and ABI guarantees asOption<U>
.E.g.
I'm trying to lean on this guarantee to implement FFI for a Rust function that wants to use the implied semantics of returning
Result<(), NonZeroU32>
to mean "a non-zero u32 error result, if any":This code compiles, and generates no warnings about unsafe FFI type usage with rust stable.
However, the
cbindgen
(0.27.0) result is not what I expect:If I change
may_fail
to returnOption<NonZeroU32>
, I get the results I expected, but I've lost the implied semantics I want to maintain on the Rust-side:Is there a workaround I could use to get
cbindgen
to play nice with "stable representation"Result
instances? Is my understanding flawed in some other way?Thanks!
The text was updated successfully, but these errors were encountered: