Skip to content

Commit e8cf052

Browse files
committed
allow Spawn!() to accept a function as argument
1 parent a690b4d commit e8cf052

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/lib.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ pub fn get_capability(issuer: &Address, params: &str) -> Option<Capability> {
311311
/// The `Spawn!()` macro is defined here as a no-op.
312312
/// However, in practice, `kit build` will rewrite it during pre-processing.
313313
///
314-
/// Example:
314+
/// Examples:
315315
/// ```no_run
316316
/// fn init(our: Address) {
317317
/// let parent = our.clone();
@@ -328,8 +328,20 @@ pub fn get_capability(issuer: &Address, params: &str) -> Option<Capability> {
328328
/// the generated child and send a [`Request()`] to pass in the closure's args.
329329
/// 3. Update the relevant metadata for the package
330330
/// (i.e. `Cargo.toml`, `metadata.json`, etc.).
331+
///
332+
///
333+
/// ```no_run
334+
/// fn init(our: Address) {
335+
/// let parent = our.clone();
336+
/// Spawn!(my_function(parent));
337+
/// ...
338+
/// }
339+
/// ```
331340
#[macro_export]
332341
macro_rules! Spawn {
333-
// Match one or more type-annotated parameters
342+
// Pattern 1: Match closure with type-annotated parameters
334343
(|$($param:ident : $type:ty),+ $(,)?| $body:block) => {};
344+
345+
// Pattern 2: Match function call
346+
($fn_name:ident($($arg:expr),* $(,)?)) => {};
335347
}

0 commit comments

Comments
 (0)