在此范围内找不到宏

时间:2018-08-01 16:09:42

标签: macros rust

我一直在尝试添加我的宏,但没有成功。签出代码:

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()),)*)
    }}
}

我收到的错误消息是:error: cannot find macro `scan!` in this scope= help: have you added the `#[macro_use]` on the module/import?

我只是在尝试创建一个宏,该宏将在此项目中用作scanf。

0 个答案:

没有答案