Crate marker_trait

source ·
Expand description

Implement a blanket implementation for a marker trait.

MASTER CI status crates.io badge docs.rs badge dependencies badge

Basic Example

#[marker_trait::marker_trait]
pub trait AsyncTask: Send + 'static {}

struct MySendStatic;
static_assertions::assert_impl_all!(MySendStatic: Send, AsyncTask);

Generated output:

pub trait AsyncTask: Send + 'static {}
impl<T: Send + 'static> AsyncTask for T {}

Sealed example

#[marker_trait::marker_trait(sealed)]
pub trait AsyncTask: Send + 'static {}

struct MySendStatic;
static_assertions::assert_impl_all!(MySendStatic: Send, AsyncTask, __SealModuleForAsyncTask__::Sealed);

Generated output:

pub trait AsyncTask: Send + 'static + __SealModuleForAsyncTask__::Sealed {}
mod __SealModuleForAsyncTask__ {
   use super::*;

    impl<__AsyncTaskImplementor__> Sealed for __AsyncTaskImplementor__
      where __AsyncTaskImplementor__: Send + 'static {}

    pub trait Sealed {}
}
#[automatically_derived]
impl<__MarkerTrait__: Send + 'static + __SealModuleForAsyncTask__::Sealed> AsyncTask for __MarkerTrait__ {}

Attribute Macros