Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
梦境迷离
Cs Summary Reflection
提交
b0ff8432
C
Cs Summary Reflection
项目概览
梦境迷离
/
Cs Summary Reflection
11 个月 前同步成功
通知
4
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
C
Cs Summary Reflection
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
b0ff8432
编写于
3月 13, 2020
作者:
梦境迷离
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add module
上级
d39557bd
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
79 addition
and
1 deletion
+79
-1
rust-examples/Cargo.toml
rust-examples/Cargo.toml
+1
-1
rust-examples/src/main.rs
rust-examples/src/main.rs
+3
-0
rust-examples/src/modules.rs
rust-examples/src/modules.rs
+75
-0
未找到文件。
rust-examples/Cargo.toml
浏览文件 @
b0ff8432
...
...
@@ -3,7 +3,7 @@ name = "rust-examples"
version
=
"0.1.0"
authors
=
[
"梦境迷离 <liguobin@growingio.com>"
]
edition
=
"2018"
#build = "build.rs" 构建前操作
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
rust-examples/src/main.rs
浏览文件 @
b0ff8432
...
...
@@ -7,11 +7,13 @@ use crate::custom_types::*;
use
crate
::
flow_control
::
*
;
use
crate
::
formatted_print
::
*
;
use
crate
::
functions
::
*
;
use
crate
::
modules
::
*
;
use
crate
::
primitives
::
*
;
use
crate
::
types
::
*
;
use
crate
::
variable_bindings
::
*
;
pub
mod
formatted_print
;
pub
mod
modules
;
pub
mod
functions
;
pub
mod
flow_control
;
pub
mod
closures
;
...
...
@@ -31,4 +33,5 @@ fn main() {
flow_control
();
functions
();
closures
();
modules
();
}
rust-examples/src/modules.rs
0 → 100644
浏览文件 @
b0ff8432
///模块
pub
fn
modules
()
{
struct_visibility
();
cfg
();
}
fn
struct_visibility
()
{
mod
my
{
//公有结构体和公有字段
pub
struct
OpenBox
<
T
>
{
pub
contents
:
T
,
}
//公有结构体和私有字段
#[allow(dead_code)]
//禁用编译器的 未使用警告
pub
struct
ClosedBox
<
T
>
{
contents
:
T
,
}
impl
<
T
>
ClosedBox
<
T
>
{
//公有的构造函数
pub
fn
new
(
contents
:
T
)
->
ClosedBox
<
T
>
{
ClosedBox
{
contents
:
contents
,
}
}
}
}
let
open_box
=
my
::
OpenBox
{
contents
:
"public information"
};
println!
(
"The open box contains: {}"
,
open_box
.contents
);
//ERROR
//let closed_box = my::ClosedBox { contents: "classified information" };
//使用构造函数可以
let
_
closed_box
=
my
::
ClosedBox
::
new
(
"classified information"
);
//ERROR
//println!("The closed box contains: {}", _closed_box.contents);
}
fn
use_declaration
()
{
//指定别名
// use deeply::nested::function as other_function;
// other_function();
//相对路径,父级和当前级
//super 和 self
}
//extern crate rary; 导入library库
fn
cfg
()
{
// This function only gets compiled if the target OS is linux
#[cfg(target_os
=
"linux"
)]
fn
are_you_on_linux
()
{
println!
(
"You are running linux!"
);
}
// And this function only gets compiled if the target OS is *not* linux
#[cfg(not(target_os
=
"linux"
))]
fn
are_you_on_linux
()
{
println!
(
"You are *not* running linux!"
);
}
are_you_on_linux
();
println!
(
"Are you sure?"
);
if
cfg!
(
target_os
=
"linux"
)
{
//target_os由rustc隐式提供,但是自定义条件条件必须使用--cfg标志传递给rustc
println!
(
"Yes. It's definitely linux!"
);
}
else
{
println!
(
"Yes. It's definitely *not* linux!"
);
}
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录