target

Attribute Macro target 

Source
#[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 of implement macro.
  • newer_type … Set path to newer_type crate. Defaults to ::newer_type. Example: ::your_crate::_export::newer_type.
  • repeater … Absolute path to the Repeater crate. see the example section. The Repeater trait 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!();