ambisync_macros 0.1.0

Proc-macro implementation for the ambisync crate
Documentation
  • Coverage
  • 100%
    6 out of 6 items documented0 out of 5 items with examples
  • Size
  • Source code size: 137.6 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 391.1 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 5s Average build duration of successful builds.
  • all releases: 5s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • LDeakin/ambisync
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • LDeakin

ambisync

Write the async form once; #[ambisync] derives the sync variant mechanically.

Libraries that ship both sync and async APIs maintain parallel code paths. These paths are often identical except for .await points, item names (for example, read / async_read and Store / AsyncStore), test attributes, and feature gates. ambisync can collapse a sync and async fn, trait, impl, struct, enum, or test into into a single async-written item. For example:

use ambisync::ambisync;

#[ambisync(
    sync(name = "read", types(AsyncStore => Store)),
    async(feature = "async"),
)]
pub async fn async_read(store: &AsyncStore, key: &str) -> Option<Vec<u8>> {
    store.get(key).await
}

which expands to:

#[cfg(feature = "async")]
pub async fn async_read(store: &AsyncStore, key: &str) -> Option<Vec<u8>> {
    store.get(key).await
}

pub fn read(store: &Store, key: &str) -> Option<Vec<u8>> {
    store.get(key)
}

#[ambisync] covers fn, trait, impl, struct, enum, and tests, with:

  • explicit naming and token-level substitution via one pair of rename tables — fns(...) for the fn namespace, types(...) for the type namespace — holding exact A => B entries and "Async{}" / "{}_async"-style pattern entries, applied to item names, type references, calls, doc comments, and intra-doc links;
  • marker macros (alt!, sync_only!, async_only!) for the minority of code that genuinely diverges;
  • explicit outer declarations when one variant needs its own docs, attributes, or signature spelling;
  • module-wide shared defaults via #[ambisync::scope] / scoped!;
  • async_trait emission with configurable Send-ness for wasm targets.

See the crate documentation for the full guide.

Licence

ambisync is licensed under either of

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.