5
我试图编写一个需要use
几个项目的宏。这适用于每个文件一次使用,但对我来说感觉很脏。有没有更好的方法直接引用这些项目,例如impl std::ops::Add for $t
或其他?谢谢!在宏中使用``的正确方法
#[macro_export]
macro_rules! implement_measurement {
($($t:ty)*) => ($(
// TODO: Find a better way to reference these...
use std::ops::{Add,Sub,Div,Mul};
use std::cmp::{Eq, PartialEq};
use std::cmp::{PartialOrd, Ordering};
impl Add for $t {
type Output = Self;
fn add(self, rhs: Self) -> Self {
Self::from_base_units(self.get_base_units() + rhs.get_base_units())
}
}
impl Sub for $t {
type Output = Self;
fn sub(self, rhs: Self) -> Self {
Self::from_base_units(self.get_base_units() - rhs.get_base_units())
}
}
// ... others ...
))
}
绝对路径正是我所期待的。谢谢! – jocull