File tree Expand file tree Collapse file tree 4 files changed +39
-10
lines changed
Expand file tree Collapse file tree 4 files changed +39
-10
lines changed Original file line number Diff line number Diff line change 11[package ]
22name = " clonelicious"
3- version = " 1.1.1 "
3+ version = " 2.0.0 "
44edition = " 2024"
55authors = [" ltpp-universe <root@ltpp.vip>" ]
66license = " MIT"
@@ -15,6 +15,9 @@ exclude = [
1515 " .github"
1616]
1717
18+ [dev-dependencies ]
19+ tokio = { version = " 1.45.0" , features = [" full" ] }
20+
1821[profile .dev ]
1922incremental = false
2023opt-level = 3
Original file line number Diff line number Diff line change @@ -26,14 +26,25 @@ cargo add clonelicious
2626
2727``` rust
2828use clonelicious :: * ;
29+
2930let s1 : String = String :: from (" Hello" );
3031let s2 : String = String :: from (" World" );
31- let res : String = clone! (s1 , s2 , {
32+ let res : String = clone! (s1 , s2 => {
3233 assert_eq! (s1 , String :: from (" Hello" ));
3334 assert_eq! (s2 , String :: from (" World" ));
3435 format! (" {} {}" , s1 , s2 )
3536});
3637assert_eq! (res , String :: from (" Hello World" ));
38+
39+ let s1 : String = String :: from (" Hello" );
40+ let s2 : String = String :: from (" World" );
41+ let res : String = clone! (s1 , s2 => async move {
42+ assert_eq! (s1 , String :: from (" Hello" ));
43+ assert_eq! (s2 , String :: from (" World" ));
44+ format! (" {} {}" , s1 , s2 )
45+ })
46+ . await ;
47+ assert_eq! (res , String :: from (" Hello World" ));
3748```
3849
3950## License
Original file line number Diff line number Diff line change 1- #[ test]
2- fn test_clone ( ) {
1+ #[ cfg( test) ]
2+ #[ tokio:: test]
3+ async fn test_clone ( ) {
34 use crate :: * ;
5+
46 let s1: String = String :: from ( "Hello" ) ;
57 let s2: String = String :: from ( "World" ) ;
6- let res: String = clone ! ( s1, s2, {
8+ let res: String = clone ! ( s1, s2 => {
79 assert_eq!( s1, String :: from( "Hello" ) ) ;
810 assert_eq!( s2, String :: from( "World" ) ) ;
911 format!( "{} {}" , s1, s2)
1012 } ) ;
1113 assert_eq ! ( res, String :: from( "Hello World" ) ) ;
14+
15+ let s1: String = String :: from ( "Hello" ) ;
16+ let s2: String = String :: from ( "World" ) ;
17+ let res: String = clone ! ( s1, s2 => async move {
18+ assert_eq!( s1, String :: from( "Hello" ) ) ;
19+ assert_eq!( s2, String :: from( "World" ) ) ;
20+ format!( "{} {}" , s1, s2)
21+ } )
22+ . await ;
23+ assert_eq ! ( res, String :: from( "Hello World" ) ) ;
1224}
Original file line number Diff line number Diff line change 2020/// but don't want to manually clone each value before passing it into the closure.
2121#[ macro_export]
2222macro_rules! clone {
23- ( $( $var: ident ) ,* , $body: block ) => { {
24- $(
25- let $var = $var. clone( ) ;
26- ) *
27- $body
23+ ( $( $var: ident ) ,* => { $( $body: tt) * } ) => { {
24+ $( let $var = $var. clone( ) ; ) *
25+ { $( $body) * }
26+ } } ;
27+
28+ ( $( $var: ident ) ,* => async move { $( $body: tt) * } ) => { {
29+ $( let $var = $var. clone( ) ; ) *
30+ async move { $( $body) * }
2831 } } ;
2932}
You can’t perform that action at this time.
0 commit comments