Key words of rust question and answer


The function of trust starts with the keyword FN, which is short for function. The main function is a function with no parameters and no return value.

fn main() {
    println!("Hello, world!");

The main function above is the main program entry function. The executable program must have the main function as the program entrance, but for the library function, the main function is not necessary.

Take simple addition as an example. Define an add function, input two int type parameters X and y, and return the int type.

If C #, the function should be written like this

int add(int x, int y)
    return x + y;

For trust, a more explicit definition of data type is needed, because for C # int refers to int32, so the corresponding addition function of trust should be

fn add(x:i32, y:i32) -> i32 {
    return x + y;

This work adoptsCC agreementReprint must indicate the author and the link of this article

Recommended Today

Video compatibility in wechat

1. In line properties of video tag SRC: URL of video Poster: Video cover, no picture displayed when playing Preload: preload Autoplay: autoplay Loop: loop playback Controls: browser’s own control bar Width: video width Height: video height style=”object-fit:fill” /Adding this style will make the Android / Web video full screen in wechat. If it is […]