我正尝试使用我在独立模块中创建的宏。参照this SO question,我已经导入了一个宏罚款。但是看来我有为什么我必须在客户端库中公开宏实现的'use'?
更新添加宏实现
lib.rs
#![macro_use]
use std::fmt;
use std::ffi::CString;
use std::ffi::CStr;
use std::str;
extern crate libc;
pub enum DbaxError {
DBAXException(String)
}
#[macro_export]
macro_rules! dbax_call_test {
($func : expr) => {
{
let call_c_func = unsafe { dbax_function(CString::new($func).unwrap().as_ptr(),0) };
match unsafe { getErrorCode() as i32 } {
0 => Ok("Done".to_owned() + $func),
_ => Err(DbaxError::DBAXException(str::from_utf8(unsafe { CStr::from_ptr(getError()) }.to_bytes()).unwrap().to_string()))
}
}
}
}
和main.rs在一个单独的箱子
// Import macro
#[macro_use] extern crate rustdbax;
// Import implementation details of macro
use rustdbax::*;
use std::ffi::CString;
use std::ffi::CStr;
use std::str;
fn main() {
// Call my macro
dbax_call_test!("DateAdd");
}
这工作得很好,但use std::*
行都是lib.rs
中实现的一部分。
为什么我必须在客户端库中公开实现的'use'?作为扩展的一部分,不应该生锈,包括lib.rs
中的任何内容?