Skip to content

Commit d2d5487

Browse files
committed
Change the return type of the signal macro from #ty to std::cell::Ref<'static, #ty> to avoid strong constraints on Copy or Clone.
1 parent 67b0609 commit d2d5487

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

macros/src/lib.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ use syn::{Expr, Ident, ItemFn, ItemStatic, ReturnType, parse_macro_input};
2424
///
2525
/// signal!(static mut A: i32 = 10;);
2626
///
27-
/// assert_eq!(A(), 10);
28-
/// assert_eq!(A_get(), 10);
27+
/// assert_eq!(*A(), 10);
28+
/// assert_eq!(*A_get(), 10);
2929
/// assert!(A_set(20));
30-
/// assert_eq!(A(), 20);
30+
/// assert_eq!(*A(), 20);
3131
/// assert!(!A_set(20)); // No change
3232
/// ```
3333
///
@@ -88,8 +88,8 @@ pub fn signal(input: TokenStream) -> TokenStream {
8888
#vis #static_token #mutability #ident_p #colon_token #lazy_ty #eq_token #expr #semi_token
8989

9090
#[allow(non_snake_case)]
91-
pub fn #ident_get() -> #ty {
92-
unsafe { *#ident_p.get() }
91+
pub fn #ident_get() -> std::cell::Ref<'static, #ty> {
92+
unsafe { #ident_p.get() }
9393
}
9494

9595
#[allow(non_snake_case)]
@@ -98,7 +98,7 @@ pub fn signal(input: TokenStream) -> TokenStream {
9898
}
9999

100100
#[allow(non_snake_case)]
101-
pub fn #ident_fn() -> #ty {
101+
pub fn #ident_fn() -> std::cell::Ref<'static, #ty> {
102102
#ident_get()
103103
}
104104
};

macros/tests/dep.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,19 @@ signal!(
1717
);
1818

1919
signal!(
20-
static mut B: i32 = 5;
20+
static mut B: String = 5.to_string();
2121
);
2222

2323
pub fn source_a() -> i32 {
2424
SOURCE_A_CALLED.set(true);
2525

26-
A_get()
26+
*A_get()
2727
}
2828

2929
pub fn source_b() -> i32 {
3030
SOURCE_B_CALLED.set(true);
3131

32-
B()
32+
B().parse::<i32>().unwrap()
3333
}
3434

3535
#[memo]

macros/tests/effect.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,19 @@ signal!(
1616
);
1717

1818
signal!(
19-
static mut B: i32 = 5;
19+
static mut B: String = 5.to_string();
2020
);
2121

2222
pub fn source_a() -> i32 {
2323
unsafe { SOURCE_A_CALLED += 1 };
2424

25-
A_get()
25+
*A_get()
2626
}
2727

2828
pub fn source_b() -> i32 {
2929
unsafe { SOURCE_B_CALLED += 1 };
3030

31-
B()
31+
B().parse::<i32>().unwrap()
3232
}
3333

3434
#[memo]

0 commit comments

Comments
 (0)