Const and static

Rust has two types of constants: consts and statics. Consts are sort of like aliases: their contents are sort of replaced on the place where they are used. The syntax is like this:

const PI: f32 = 3.1415927; 

Statics are more like variables. They have a global scope of the program, and are defined as follows:

static MY_VARIABLE: i32 = 255; 

They cannot be altered.

Rust is able to guess the types of local function variables. This is called local type inference. However, it is only local, so types of statics and consts must always be typed out.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset