[英]How to specify the representation type for an enum in Rust to interface with C++?
有没有办法在Rust中使用显式表示类型进行C ++样式枚举? 例:
enum class Number: int16_t {
Zero, One, Two, Three, Four, Five, Six, Seven, Eight, Nine
};
如果没有,还有另一种方法可以组织这样的变量吗? 我正在与外部库连接,因此指定类型很重要。 我知道我可以这样做:
type Number = int16_t;
let One: Number = 1;
let Two: Number = 2;
let Three: Number = 3;
但在我看来,这引入了很多冗余;
注意这个问题不是重复的是否可以在Rust中包装C枚举? 因为它是关于包装C ++,而不是包装C.
您可以为枚举指定表示形式。
#[repr(i16)]
enum Foo {
One = 1,
Two = 2,
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.