feat: add proc macro to reduce overseer mock boilerplate (#2949)

This commit is contained in:
Bernhard Schuster
2021-04-29 12:07:28 +02:00
committed by GitHub
parent f36d8efb3d
commit 1ef8eac8ec
12 changed files with 309 additions and 487 deletions
@@ -0,0 +1,13 @@
#![allow(dead_code)]
use polkadot_procmacro_overseer_subsystems_gen::AllSubsystemsGen;
#[derive(Clone, AllSubsystemsGen)]
enum AllSubsystems<A,B> {
A(A),
B(B),
}
fn main() {
let all = AllSubsystems::<u8,u16>::A(0u8);
}
@@ -0,0 +1,5 @@
error: expected `struct`
--> $DIR/err-01-enum.rs:6:1
|
6 | enum AllSubsystems<A,B> {
| ^^^^
@@ -0,0 +1,17 @@
#![allow(dead_code)]
use polkadot_procmacro_overseer_subsystems_gen::AllSubsystemsGen;
#[derive(Clone, AllSubsystemsGen)]
struct AllSubsystems<X> {
a: X,
b: X,
}
fn main() {
let all = AllSubsystems::<u16> {
a: 0_u16,
b: 1_u16,
};
let _all = all.replace_a(77u8);
}
@@ -0,0 +1,14 @@
error: Generic type parameters may only be used for exactly one field, but is used more than once.
--> $DIR/err-01-generic-used-twice.rs:7:5
|
7 | a: X,
| ^
error[E0599]: no method named `replace_a` found for struct `AllSubsystems<u16>` in the current scope
--> $DIR/err-01-generic-used-twice.rs:16:17
|
6 | struct AllSubsystems<X> {
| ----------------------- method `replace_a` not found for this
...
16 | let _all = all.replace_a(77u8);
| ^^^^^^^^^ method not found in `AllSubsystems<u16>`
@@ -0,0 +1,17 @@
#![allow(dead_code)]
use polkadot_procmacro_overseer_subsystems_gen::AllSubsystemsGen;
#[derive(Clone, AllSubsystemsGen)]
struct AllSubsystems {
a: f32,
b: u16,
}
fn main() {
let all = AllSubsystems {
a: 0_f32,
b: 1_u16,
};
let _all = all.replace_a(77u8);
}
@@ -0,0 +1,14 @@
error: Generic type parameters may only be used once have at least one generic parameter.
--> $DIR/err-01-no-generics.rs:7:5
|
7 | a: X,
| ^
error[E0599]: no method named `replace_a` found for struct `AllSubsystems<u16>` in the current scope
--> $DIR/err-01-no-generics.rs:16:17
|
6 | struct AllSubsystems<X> {
| ----------------------- method `replace_a` not found for this
...
16 | let _all = all.replace_a(77u8);
| ^^^^^^^^^ method not found in `AllSubsystems<u16>`
@@ -0,0 +1,17 @@
#![allow(dead_code)]
use polkadot_procmacro_overseer_subsystems_gen::AllSubsystemsGen;
#[derive(Clone, AllSubsystemsGen)]
struct AllSubsystems<A, B> {
a: A,
b: B,
}
fn main() {
let all = AllSubsystems::<u8, u16> {
a: 0u8,
b: 1u16,
};
let _all: AllSubsystems<_,_> = all.replace_a::<u32>(777_777u32);
}