美文网首页
Rust 入门 - 方法

Rust 入门 - 方法

作者: Lee_dev | 来源:发表于2021-05-25 14:11 被阅读0次

函数/方法

无返回值

fn say_hello(name: String) {
    println!("hello {} !", name);
}

let name = "Tom";
say_hello(name.to_string());

有返回值

fn sum(a: isize, b: isize) -> isize {
    return a + b;
}

fn sum1(a: isize, b: isize) -> isize {
    a + b
}

语句不会返回值,表达式会返回值

let y = {
    8 + 8
};
println!("y = {}",y);

相关文章

  • Rust 入门 - 方法

    函数/方法 无返回值 有返回值 语句不会返回值,表达式会返回值

  • Rust 问答之 Cargo 是什么

    Cargo:Rust 的构建工具和包管理器 文章标题来自于 Rust 官网: 入门 - Rust 程序设计语言 在...

  • Rust CLI应用程序的入门模板:rust-starter

    rust-starter是一个创建Rust CLI应用程序的入门模板。 特性 Clap[https://githu...

  • Rust 入门 (Rust Rocks)

    缘起 实践出真知快速获取澄清概念OwnershipMoveReferenceMutable reference解释...

  • 2020 Rust 入门结构体方法

    最近学习无人驾驶,在无人驾驶中用到最多语言是 cpp 这样相对底层语言。那么我们除了 cpp 现在多了 rust ...

  • Rust语言入门

    一、简介 Rust是Mozilla公司推出的一门全新的编程语言,1.0版本于2015年5月15日正式对外发布。作为...

  • Rust 入门 - HashMap

    导入库 使用 vector 和 hashmap 数据都在堆上 用队伍列表和分数列表创建哈希 map 哈希 map ...

  • Rust 入门 - Slice

    Slice 另一个没有所有权的数据类型是 slice。slice 允许你引用集合中一段连续的元素序列,而不用引用整...

  • Rust 入门 - 类型

    类型 布尔类型 char类型, 在 Rust 中 char 是32位的 数字类型i8, i16, i32, i64...

  • Rust 入门 - Cargo

    cargo 创建工程 检查语法 编译 编译并运行

网友评论

      本文标题:Rust 入门 - 方法

      本文链接:https://www.haomeiwen.com/subject/tyaqsltx.html