What this attribute means?

I just completed rust book and trying to explore projects. In many projects i have seen an attribute like this. For ex:

#[tokio::main]
or
#[pallet::pallet]

``
What is this means?
1 Like

It means a main proc macro under tokio or pallet path (specifically from the root of the corresponding crate).

For reference

Attribute macros define new outer attributes which can be attached to items
src: Procedural Macros - The Rust Reference

and the syntax notation of OuterAttribute

OuterAttribute :
# [ Attr ]

Attr :
SimplePath AttrInput ?

and the syntax of Simple Paths

SimplePath :
:: ? SimplePathSegment (:: SimplePathSegment)*

SimplePathSegment :
IDENTIFIER | super | self | crate | $crate

4 Likes

In particular, tokio::main lets you write an async main() function that is run by the tokio async runtime.

I'm not familiar with pallet, and I don't see a pallet::pallet attribute in its docs.

Based on the example provided, it should be a helper attribute for the DocumentLike derive. I'm unsure if you can use fully qualified paths on helper attributes though.

1 Like