Sto provando a scrivere una macro che necessita di use
alcuni elementi. Questo è adatto per un uso per file, ma mi sembra sporco. C'è un modo migliore per fare riferimento direttamente agli elementi, ad esempio impl std::ops::Add for $t
o qualcosa del genere? Grazie!Modo corretto per "utilizzare" in una macro
#[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 ...
))
}
Il percorso assoluto era esattamente quello che stavo cercando. Grazie! – jocull