#![cfg_attr(not(feature = "std"), no_std)]
2 Answers
Those are conditional attributes, a feature of rust. In a nutshell you say if not(feature = "std")
is true i.e. feature std
is disabled, then turn on attribute called no_std
module wide as indicated by the !
after pound #
. Enabling no_std
prevents you from importing the rust std lib and making use of it. This is necessary for pallets as they run inside a wasm interpreter and do not have access to machine resources which is in turn required by rust std lib.
In short, it means: If "std"
is not enabled, flag/mark this crate/module as no_std
while compiling.
All you need is this: https://doc.rust-lang.org/reference/conditional-compilation.html