Skip to content

Commit bec85f5

Browse files
committed
Refactor: make macros a public crate for publishing
`macros` is renamed to `openraft-macros` and will be published to crates.io so that Openraft-0.9 that relies on it can be published.
1 parent 23e856b commit bec85f5

File tree

15 files changed

+47
-16
lines changed

15 files changed

+47
-16
lines changed

macros/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[package]
2-
name = "macros"
2+
name = "openraft-macros"
33

44
version = { workspace = true }
55
edition = { workspace = true }

macros/src/lib.rs

+12-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![doc = include_str!("lib_readme.md")]
2+
13
use proc_macro::TokenStream;
24
use quote::quote;
35
use syn::parse2;
@@ -11,7 +13,7 @@ use syn::Type;
1113

1214
/// This proc macro attribute optionally adds `Send` bounds to a trait.
1315
///
14-
/// By default, `Send` bounds will be added to the trait and to the return bounds of any async
16+
/// By default, `Send` bounds will be added to the trait and to the return bounds of any async
1517
/// functions defined withing the trait.
1618
///
1719
/// If the `singlethreaded` feature is enabled, the trait definition remains the same without any
@@ -20,14 +22,22 @@ use syn::Type;
2022
/// # Example
2123
///
2224
/// ```
23-
/// use macros::add_async_trait;
25+
/// use openraft_macros::add_async_trait;
2426
///
2527
/// #[add_async_trait]
2628
/// trait MyTrait {
2729
/// async fn my_method(&self) -> Result<(), String>;
2830
/// }
2931
/// ```
3032
///
33+
/// The above code will be transformed into:
34+
///
35+
/// ```ignore
36+
/// trait MyTrait {
37+
/// fn my_method(&self) -> impl Future<Output=Result<(), String>> + Send;
38+
/// }
39+
/// ```
40+
///
3141
/// Note: This proc macro can only be used with traits.
3242
///
3343
/// # Panics

macros/src/lib_readme.md

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
Supporting utils for [Openraft](https://crates.io/crates/openraft).
2+
3+
`#[add_async_trait]` adds `Send` bounds to an async trait.
4+
5+
# Example
6+
7+
```
8+
#[openraft_macros::add_async_trait]
9+
trait MyTrait {
10+
async fn my_method(&self) -> Result<(), String>;
11+
}
12+
```
13+
14+
The above code will be transformed into:
15+
16+
```ignore
17+
trait MyTrait {
18+
fn my_method(&self) -> impl Future<Output=Result<(), String>> + Send;
19+
}
20+
```

memstore/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# openraft-memstore
22

3-
This is an in-memory example `RaftStorage` implementation based on [openraft-0.8](https://github.com/datafuselabs/openraft/tree/release-0.8).
3+
This is an in-memory example `RaftLogStorage` and `RaftStateMachine` implementation based on [openraft](https://github.com/datafuselabs/openraft/).
44

55
This crate is built mainly for testing or demonstrating purpose.:)

openraft/Cargo.toml

+3-2
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,15 @@ keywords = { workspace = true }
1313
license = { workspace = true }
1414
repository = { workspace = true }
1515

16+
1617
[dependencies]
1718
anyerror = { workspace = true }
1819
anyhow = { workspace = true, optional = true }
1920
byte-unit = { workspace = true }
2021
clap = { workspace = true }
2122
derive_more = { workspace = true }
2223
futures = { workspace = true }
23-
macros = { path = "../macros" }
24+
openraft-macros = { path = "../macros", version = "0.9.0" }
2425
maplit = { workspace = true }
2526
rand = { workspace = true }
2627
serde = { workspace = true, optional = true }
@@ -80,7 +81,7 @@ compat = []
8081
storage-v2 = []
8182

8283
# Disallows applications to share a raft instance with multiple threads.
83-
singlethreaded = ["macros/singlethreaded"]
84+
singlethreaded = ["openraft-macros/singlethreaded"]
8485

8586

8687
# Permit the follower's log to roll back to an earlier state without causing the

openraft/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,10 @@ mod try_as_ref;
6868

6969
pub use anyerror;
7070
pub use anyerror::AnyError;
71-
pub use macros::add_async_trait;
7271
pub use network::RPCTypes;
7372
pub use network::RaftNetwork;
7473
pub use network::RaftNetworkFactory;
74+
pub use openraft_macros::add_async_trait;
7575
pub use type_config::RaftTypeConfig;
7676

7777
pub use crate::async_runtime::AsyncRuntime;

openraft/src/network/factory.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use macros::add_async_trait;
1+
use openraft_macros::add_async_trait;
22

33
use crate::network::RaftNetwork;
44
use crate::OptionalSend;

openraft/src/network/network.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::future::Future;
22
use std::time::Duration;
33

4-
use macros::add_async_trait;
4+
use openraft_macros::add_async_trait;
55

66
use crate::error::Fatal;
77
use crate::error::RPCError;

openraft/src/network/snapshot_transport.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::io::SeekFrom;
66
use std::time::Duration;
77

88
use futures::FutureExt;
9-
use macros::add_async_trait;
9+
use openraft_macros::add_async_trait;
1010
use tokio::io::AsyncReadExt;
1111
use tokio::io::AsyncSeekExt;
1212
use tokio::io::AsyncWriteExt;

openraft/src/runtime/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use macros::add_async_trait;
1+
use openraft_macros::add_async_trait;
22

33
use crate::engine::Command;
44
use crate::RaftTypeConfig;

openraft/src/storage/log_store_ext.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::fmt::Debug;
22
use std::ops::RangeBounds;
33

4-
use macros::add_async_trait;
4+
use openraft_macros::add_async_trait;
55

66
use crate::defensive::check_range_matches_entries;
77
use crate::LogId;

openraft/src/storage/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use std::ops::RangeBounds;
1414
#[cfg(not(feature = "storage-v2"))] pub use adapter::Adaptor;
1515
pub use helper::StorageHelper;
1616
pub use log_store_ext::RaftLogReaderExt;
17-
use macros::add_async_trait;
17+
use openraft_macros::add_async_trait;
1818
pub use snapshot_signature::SnapshotSignature;
1919
pub use v2::RaftLogStorage;
2020
pub use v2::RaftLogStorageExt;

openraft/src/storage/v2.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
55
mod raft_log_storage_ext;
66

7-
use macros::add_async_trait;
7+
use openraft_macros::add_async_trait;
88
pub use raft_log_storage_ext::RaftLogStorageExt;
99

1010
use crate::storage::callback::LogFlushed;

openraft/src/storage/v2/raft_log_storage_ext.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use anyerror::AnyError;
2-
use macros::add_async_trait;
2+
use openraft_macros::add_async_trait;
33

44
use crate::storage::LogFlushed;
55
use crate::storage::RaftLogStorage;

openraft/src/testing/store_builder.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#[cfg(not(feature = "storage-v2"))] use std::future::Future;
22

3-
use macros::add_async_trait;
3+
use openraft_macros::add_async_trait;
44

55
#[cfg(not(feature = "storage-v2"))] use crate::storage::Adaptor;
66
use crate::storage::RaftLogStorage;

0 commit comments

Comments
 (0)