fred-macros

Crates.iofred-macros
lib.rsfred-macros
version0.1.0
sourcesrc
created_at2024-09-03 17:10:04.986322
updated_at2024-09-03 17:10:04.986322
descriptionProcedural macros for the `fred` Redis client
homepagehttps://github.com/aembke/fred-macros
repositoryhttps://github.com/aembke/fred-macros
max_upload_size
id1361868
size16,722
Alec Embke (aembke)

documentation

README

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 { () }
  }
}
Commit count: 0

cargo fmt