通过golang和rust代码对比快速学习rust (1)

1. fmt.Println

Golang代码

package main

import "fmt"

func main() {
fmt.Println("Hello, 世界!")
}

Rust代码

fn main() {
println!("Hello, 世界!");
}

2. fmt.Printf

Golang代码

package main

import "fmt"

func main() {
var s = "世界"
var sum = 10
fmt.Printf("Hello, %s!",s)
fmt.Printf("3 +7 = %d",sum)
}

Rust代码

fn main() {
let s = "世界"
let sum = 10
println!("Hello, {}!", s);
println!("3 + 7 = {}", sum);
}