1 个不稳定版本
0.1.1 | 2024年6月15日 |
---|---|
0.1.0 |
|
#231 在 FFI
331 每月下载量
在 3 crates 中使用
9KB
#[ensure_uniform_type]
: 在编译时确保统一结构字段类型
一个编译时检查,确保类型在其字段中使用统一类型。
此宏的一个示例用途是确保结构 #[repr(C)]
布局可以正确地映射到(统一)字段类型的切片。
示例
假设以下类型
#[ensure_uniform_type]
pub struct Example<T>
{
/// First field
x: T,
// Different type
offending: u32,
}
上面的代码将无法编译,而是给出错误
error: Struct DifferentialDriveState has fields of different types. Expected uniform use of T, found u32 in field offending.
--> src/differential_drive.rs:16:1
|
16 | / /// A state of a differential drive robot, or differential wheeled robot.
18 | | #[ensure_uniform_type]
19 | | pub struct Example<T>
... |
37 | | offending: u32,
38 | | }
| |_^
相比之下,以下代码可以无错误地编译
#[ensure_uniform_type]
pub struct Example<T>
{
x: T,
not_offending: T,
}
依赖关系
~285–730KB
~18K SLoC