Sto provando a utilizzare una macro che ho creato in un modulo separato. Con riferimento a this SO question, ho importato una macro fine. Tuttavia sembra che hoPerché devo esporre l''uso' di una macro implementazione nella libreria client?
aggiornamento per aggiungere macro realizzazione
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()))
}
}
}
}
e main.rs in una cassa separata
// 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");
}
Questo funziona bene, ma le linee use std::*
fanno tutti parte dell'implementazione nello lib.rs
.
Perché devo esporre l''uso' dell'implementazione nella libreria client? Non dovrebbe arrugginire come parte della sua espansione 'includere' qualsiasi cosa fosse nello lib.rs
?