Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #[warn(dead_code)]
- #[derive(Debug)]
- enum Gpio {
- Bcm1,
- Bcm2,
- Bcm3,
- Bcm4
- }
- struct Ports {
- bcm1: Gpio,
- bcm2: Gpio,
- bcm3: Gpio,
- bcm4: Gpio,
- }
- macro_rules! foo {
- () => (());
- }
- macro_rules! port_name {
- ( &ports.$name:ident ) => ( $name );
- ( ports.$name:ident ) => ( $name );
- }
- macro_rules! port_type {
- ( (&ports.)$name:ident ) => ( &'a Gpio );
- ( (ports.)$name:ident ) => ( Gpio );
- }
- macro_rules! port_value {
- ( &ports.$name:ident ) => ( &'a ports.$name );
- ( ports.$name:ident ) => ( ports.$name );
- }
- macro_rules! configure {
- ( $peripheral:ident: $( $port:expr ),* ) => {
- #[derive(Debug)]
- struct $peripheral<'a> {
- $(
- port_name!($port): port_type!($port),
- )*
- }
- let $peripheral = $peripheral { $( a: port_value!($port)),* };
- };
- }
- fn main() {
- let ports = Ports {bcm1: Gpio::Bcm1, bcm2: Gpio::Bcm2, bcm3: Gpio::Bcm3, bcm4: Gpio::Bcm4};
- //let a = ports.bcm1;
- //let b = ports.bcm2;
- configure!(motor1: &ports.bcm1, ports.bcm2);
- //configure!(motor2: &ports.bcm1, ports.bcm3);
- /*
- #[derive(Debug)]
- struct Peripheral<'a> {
- port1: &'a Gpio,
- port2: Gpio
- }
- let motor1 = Peripheral { port1: &ports.bcm1, port2: ports.bcm2 };
- let motor2 = Peripheral { port1: &ports.bcm1, port2: ports.bcm3 };
- */
- println!("motor1:{:?}", motor1);
- println!("motor2:{:?}", motor2);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement