#[target]Expand description
Define a trait for use of implement macro.
§Arguments (all optional)
alternative… Trait. If specified, implement this trait instead of the target trait itself. The target trait is used only for an argument ofimplementmacro.newer_type… Set path tonewer_typecrate. Defaults to::newer_type. Example:::your_crate::_export::newer_type.repeater… Absolute path to theRepeatercrate. see the example section. TheRepeatertrait is defined in the same crate that the target trait is defined, and should be visible from the users, which refer to the trait with#[implement]macro.
§Example
use newer_type::target;
pub trait Repeater<const TRAIT_ID : u64, const NTH : usize, T: ?Sized> {
type Type;
}
#[target(repeater = Repeater)]
trait MyTrait {
fn my_fn(&self) -> ::core::primitive::usize;
}use newer_type::target;
type TypeFromContext = usize;
pub trait Repeater<const TRAIT_ID : u64, const NTH : usize, T: ?Sized> {
type Type;
}
#[target(repeater = Repeater)]
trait MyTrait {
fn my_fn(&self, t: TypeFromContext) -> Box<usize>;
}We recomend this pattern to set repeater path correctly.
ⓘ
use newer_type::target;
type TypeFromContext = usize;
// placed in crate root
pub trait Repeater<const TRAIT_ID : u64, const NTH : usize, T: ?Sized> {
type Type;
}
macro_rules! emit_trait {
() => {
#[target(repeater = $crate::Repeater)]
trait MyTrait {
fn my_fn(&self, t: TypeFromContext) -> Box<usize>;
}
};
}
emit_trait!();