Skip to content

Commit e143b5e

Browse files
committed
0.2.5: proxy function macros
1 parent a4845dc commit e143b5e

File tree

8 files changed

+63
-14
lines changed

8 files changed

+63
-14
lines changed

Cargo.lock

Lines changed: 40 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

batched/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "batched"
33
description = "rust macro util for batching expensive operations"
4-
version = "0.2.3"
4+
version = "0.2.5"
55
edition = "2024"
66
license = "MIT"
77
readme = "../README.md"
@@ -11,4 +11,4 @@ keywords = ["batch", "performance", "efficient"]
1111

1212
[dependencies]
1313
anyhow = "1.0.98"
14-
batched_derive = { version = "0.2.1", path = "../batched_derive" }
14+
batched_derive = { version = "0.2.5", path = "../batched_derive" }

batched_derive/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "batched_derive"
33
description = "rust macro util for batching expensive operations"
4-
version = "0.2.1"
4+
version = "0.2.5"
55
edition = "2024"
66
license = "MIT"
77
readme = "../README.md"

batched_derive/src/builder.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ fn build_identifiers(call_function: &Function) -> Identifiers {
3636
pub fn build_code(call_function: Function, options: Attributes) -> TokenStream {
3737
let identifiers = build_identifiers(&call_function);
3838

39+
let macros = &call_function.macros;
3940
let visibility = &call_function.visibility;
4041
let arg = &call_function.batched_arg;
4142
let arg_name: TokenStream = syn::parse_str(&call_function.batched_arg_name).unwrap();
@@ -123,6 +124,7 @@ pub fn build_code(call_function: Function, options: Attributes) -> TokenStream {
123124
quote! {
124125
#executor
125126

127+
#(#macros)*
126128
async fn #inner_batched(#arg) -> #returned {
127129
let result = async { #inner_body };
128130
let result = result.await;
@@ -246,7 +248,7 @@ fn build_executor(
246248
}
247249

248250
if return_channels.is_empty() {
249-
break;
251+
continue;
250252
}
251253

252254
let mut data = vec![];

batched_derive/src/parse.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use crate::utils::expr_to_u64;
99

1010
#[derive(Debug)]
1111
pub struct Function {
12+
pub macros: Vec<TokenStream>,
1213
pub identifier: String,
1314
pub visibility: TokenStream,
1415
pub inner: TokenStream,
@@ -53,6 +54,12 @@ impl Function {
5354
pub fn parse(tokens: TokenStream) -> Self {
5455
let function: ItemFn = syn::parse2(tokens).expect("invalid function");
5556

57+
let macros = function
58+
.attrs
59+
.into_iter()
60+
.map(|attr| attr.into_token_stream())
61+
.collect();
62+
5663
let visibility = function.vis.into_token_stream();
5764
let identifier = function.sig.ident.to_string();
5865
let args = function.sig.inputs;
@@ -156,6 +163,7 @@ impl Function {
156163
let batched_arg_type = batched_arg_type.unwrap();
157164

158165
Self {
166+
macros,
159167
identifier,
160168
visibility,
161169
batched_arg,

tests/Cargo.toml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@ anyhow = "1.0.98"
99
batched = { path = "../batched" }
1010
batched_derive = { path = "../batched_derive" }
1111
tokio = { version = "1.44.2", features = ["full"] }
12+
tracing = "0.1.41"
1213

1314
[[test]]
14-
name = "macros"
15-
path = "macros.rs"
15+
name = "macro"
16+
path = "src/macro.rs"
1617

1718
[[test]]
1819
name = "error"
19-
path = "error.rs"
20+
path = "src/error.rs"
File renamed without changes.

tests/macros.rs renamed to tests/src/macro.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,11 @@ async fn window() {
4747
numbers.iter().sum()
4848
}
4949

50-
let before = Instant::now();
50+
let start = Instant::now();
5151
add_multiple(vec![1, 1, 1]).await;
52-
let after = before.elapsed();
53-
assert!(after.as_secs() == 1);
52+
53+
let elapsed = start.elapsed();
54+
assert!(elapsed.as_secs() == 1);
5455
}
5556

5657
#[tokio::test]
@@ -79,5 +80,4 @@ async fn returned_iterator_with_error() {
7980

8081
let result = add_each(2).await.unwrap();
8182
assert!(result == 3);
82-
}
83-
83+
}

0 commit comments

Comments
 (0)