1

I have been trying to add my macro with no success. Check out the code:

extern crate nrf52;

#[macro_use]
use nrf52::uart::UARTE0;
use kernel::hil::uart::{self, UART};

const BUFFER_SIZE_2048: usize = 2048;

pub unsafe fn run() {
    let output = scan!("2 false fox", char::is_whitespace, u8, bool, String);

    &nrf52::uart::UARTE0.init(uart::UARTParams {
        baud_rate: 115200,
        stop_bits: uart::StopBits::One,
        parity: uart::Parity::None,
        hw_flow_control: false,
    });

    let buf = static_init!([u8; BUFFER_SIZE_2048], [0; BUFFER_SIZE_2048]);

    for (ascii_char, b) in (33..126).cycle().zip(buf.iter_mut()) {
        *b = ascii_char;
    }

    transmit_entire_buffer(buf);
}

#[allow(unused)]
unsafe fn transmit_entire_buffer(buf: &'static mut [u8]) {
    &UARTE0.transmit(buf, BUFFER_SIZE_2048);
}

macro_rules! scan {
    ( $string:expr, $sep:expr, $( $x:ty ),+ ) => {{
        let mut iter = $string.split($sep);
        ($(iter.next().and_then(|word| word.parse::<$x>().ok()),)*)
    }}
}

The error message i am getting is: error: cannot find macro `scan!` in this scope, = help: have you added the `#[macro_use]` on the module/import?

I am simply trying to create a macro that will work as a scanf in this project.

Shepmaster
  • 388,571
  • 95
  • 1,107
  • 1,366
EmbeddedOS
  • 173
  • 6
  • 18
  • I believe your question is answered by the answers of [How do I use a macro across module files?](https://stackoverflow.com/questions/26731243/how-do-i-use-a-macro-across-module-files). If you disagree, please [edit] your question to explain the differences. Otherwise, we can mark this question as already answered. – Shepmaster Aug 01 '18 at 16:15
  • 1
    TL;DR the duplicate: define your macro before using it. – Shepmaster Aug 01 '18 at 16:15
  • 1
    True sorry, i was in that post before also but i missed that part totally. Thanks .. – EmbeddedOS Aug 01 '18 at 16:20

0 Answers0