| 0.1.1 |
|
|---|---|
| 0.1.0 |
|
#186 in #macros
8KB
90 行
impl Trait 不允许在函数和方法返回类型之外使用
… 但现在允许了!
此库为你提供了一个宏,仅此一个: #[desugar_impl]。
使用 #[desugar_impl] 注释任何结构体、枚举或联合,以允许在它们的声明中使用 field_name: impl SomeTrait。例如:
#[desugar_impl]
struct Test {
a: impl Clone + PartialOrd,
b: impl Clone + PartialOrd,
c: impl Hash,
}
转换为
struct Test<Ty1, Ty2, Ty3>
where
Ty1: Clone + PartialOrd,
Ty2: Clone + PartialOrd,
Ty3: Hash,
{
a: Ty1,
b: Ty2,
c: Ty3,
}
您仍然可以在 #[desugar_impl] 下方放置任何 #[derive(…)] 宏,并且它们将与转换后的代码一起正常工作。
lib.rs:
impl Trait 不允许在函数和方法返回类型之外使用
… 但现在允许了!
此库为你提供了一个宏,仅此一个: [#[desugar_impl]][macro@desugar_impl]。
使用 [#[desugar_impl]][macro@desugar_impl] 注释任何结构体、枚举或联合,以允许在它们的声明中使用 field_name: impl SomeTrait。例如:
#[desugar_impl::desugar_impl]
struct Test {
a: impl Clone + PartialOrd,
b: impl Clone + PartialOrd,
c: impl Copy,
}
转换为
struct Test<Ty1, Ty2, Ty3>
where
Ty1: Clone + PartialOrd,
Ty2: Clone + PartialOrd,
Ty3: Copy,
{
a: Ty1,
b: Ty2,
c: Ty3,
}
您仍然可以在 #[desugar_impl] 下方放置任何 #[derive(…)] 宏,并且它们将与转换后的代码一起正常工作。
依赖项
~1.5MB
~35K SLoC