@@ -365,6 +365,42 @@ impl App {
365365 if let ForeignItem :: Fn ( mut item) = item {
366366 let span = item. sig . ident . span ( ) ;
367367 if let Some ( pos) = item
368+ . attrs
369+ . iter ( )
370+ . position ( |attr| util:: attr_eq ( attr, "init" ) )
371+ {
372+ let args = InitArgs :: parse ( item. attrs . remove ( pos) . tokens ) ?;
373+
374+ // If an init function already exists, error
375+ if init. is_some ( ) {
376+ return Err ( parse:: Error :: new (
377+ span,
378+ "`#[init]` function must appear at most once" ,
379+ ) ) ;
380+ }
381+
382+ check_ident ( & item. sig . ident ) ?;
383+
384+ init = Some ( Init :: parse_foreign ( args, item) ?) ;
385+ } else if let Some ( pos) = item
386+ . attrs
387+ . iter ( )
388+ . position ( |attr| util:: attr_eq ( attr, "idle" ) )
389+ {
390+ let args = IdleArgs :: parse ( item. attrs . remove ( pos) . tokens ) ?;
391+
392+ // If an idle function already exists, error
393+ if idle. is_some ( ) {
394+ return Err ( parse:: Error :: new (
395+ span,
396+ "`#[idle]` function must appear at most once" ,
397+ ) ) ;
398+ }
399+
400+ check_ident ( & item. sig . ident ) ?;
401+
402+ idle = Some ( Idle :: parse_foreign ( args, item) ?) ;
403+ } else if let Some ( pos) = item
368404 . attrs
369405 . iter ( )
370406 . position ( |attr| util:: attr_eq ( attr, "task" ) )
@@ -408,7 +444,8 @@ impl App {
408444 } else {
409445 return Err ( parse:: Error :: new (
410446 span,
411- "`extern` task required `#[task(..)]` attribute" ,
447+ "`extern` task, init or idle must have either `#[task(..)]`,
448+ `#[init(..)]` or `#[idle(..)]` attribute" ,
412449 ) ) ;
413450 }
414451 } else {
0 commit comments