What is the purpose of the parameter syntax of a Rust function over C?

The strange name, in any case, in the parameters of the function C is as follows:

void func_name(int a, int b) {

}

However, in Rust:

fn func_name(a: int, b: int) {

}

Is it just a preference in syntax and appeal to the creators of Rust, or is it for a specific purpose that I do not know about? For example, Go has "optional half-columns", but they actually show when the expression ends. Please keep in mind that I'm a complete newbie to Rust, so if you try to provide some bizarre examples in Rust I, you probably won't understand :(

+4
source share
2 answers

Rust, .

C:

a b = 1;
a = 2;

C :

  • in a b = 1;, a - , b - ( )
  • in a = 1;, a - , ​​ , ( ).

, C, , a , (.. , , ).

, Rust:

let a = 1;
a = 2;

let, , . - Rust (let a = ...; let a = a.foo;).

, :

let a: b = 1;
a = 2;

, , . let , a : .

Rust , (Rust LL (1)), .

, , , :

impl Foo {
    fn doit(&self);
}
+7

Rust :

let x : i32 = 0;

C , , :

let x = 0i32;

, let.

, , let . , :

fn foo(x : i32)

, ?

0

All Articles