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. See implementation of traits.

  • newer_type … Set path to newer_type crate. Defaults to ::newer_type. Example: ::your_crate::_export::newer_type.

  • implementor … a (uninhabited) struct with one generic argument, used as type_leak’s implementor type. It should be specified when you use types with relative path in the trait definition.

    §Example

    use newer_type::target;
    
    #[target]
    trait MyTrait {
        fn my_fn(&self) -> ::core::primitive::usize;
    }
    use newer_type::target;
    
    pub struct Implementor<T>(
        core::marker::PhantomData<T>,
        core::convert::Infallible
    );
    
    type TypeFromContext = usize;
    
    // Implementor should be public to all `MyTrait` users, and thus it should
    // be specified with absolute path (like
    // `::your_crate::path::to::Implementor`).
    #[target(implementor = Implementor)]
    trait MyTrait {
        fn my_fn(&self, t: TypeFromContext) -> Box<usize>;
    }

See ::newet_type::target