1 unstable release

0.1.0 Sep 3, 2024

#1209 in Procedural macros

Download history 248/week @ 2024-08-29 949/week @ 2024-09-05 918/week @ 2024-09-12 1797/week @ 2024-09-19 2006/week @ 2024-09-26 2966/week @ 2024-10-03 2991/week @ 2024-10-10 3941/week @ 2024-10-17 4634/week @ 2024-10-24 4670/week @ 2024-10-31 3733/week @ 2024-11-07 3602/week @ 2024-11-14 6171/week @ 2024-11-21 6540/week @ 2024-11-28 8245/week @ 2024-12-05 9281/week @ 2024-12-12

31,101 downloads per month
Used in 17 crates (via fred)

MIT license

14KB
189 lines

Procedural macros that conditionally change or remove Send and Sync bounds.

Examples

Item (function) Modification

extern crate fred_macros;

use fred_macros::rm_send_if;
use std::future::Future;

pub trait T1 {}
pub trait T2 {}

pub trait T3 {
  /// Documentation tests.
  #[rm_send_if(feature = "glommio")]
  fn foo<A, B>(&self, _a: A, _b: B) -> impl Future<Output=()> + Send
  where
    A: T1 + Send,
    B: T2 + Send,
  {
    async move { () }
  }
}

This will expand to:

// ...

pub trait T3 {
  /// Documentation tests.
  #[cfg(feature = "glommio")]
  fn foo<A, B>(&self, _a: A, _b: B) -> impl Future<Output=()>
  where
    A: T1,
    B: T2,
  {
    async move { () }
  }

  /// Documentation tests.
  #[cfg(not(feature = "glommio"))]
  fn foo<A, B>(&self, _a: A, _b: B) -> impl Future<Output=()> + Send
  where
    A: T1 + Send,
    B: T2 + Send,
  {
    async move { () }
  }
} 

Trait Modification

extern crate fred_macros;

use fred_macros::rm_send_if;
use std::future::Future;

trait T1 {}
trait T2 {}

/// Test trait documentation.
#[rm_send_if(feature = "glommio")]
pub trait T3: Clone + Send + Sync {
  /// Test fn documentation
  fn bar<A, B>(&self, _a: A, _b: B) -> impl Future<Output=()> + Send
  where
    A: T1 + Send,
    B: T2 + Send + Sync,
  {
    async move { () }
  }
}

This will expand to:

// ... 

#[cfg(feature = "glommio")]
pub trait T3: Clone {
  /// Test fn documentation
  fn bar<A, B>(&self, _a: A, _b: B) -> impl Future<Output=()>
  where
    A: T1,
    B: T2,
  {
    async move { () }
  }
}

#[cfg(not(feature = "glommio"))]
pub trait T3: Clone + Send + Sync {
  /// Test fn documentation
  fn bar<A, B>(&self, _a: A, _b: B) -> impl Future<Output=()> + Send
  where
    A: T1 + Send,
    B: T2 + Send + Sync,
  {
    async move { () }
  }
}

Dependencies

~225–670KB
~16K SLoC