add code
This commit is contained in:
7
13.Attributes/13 Attributes/Cargo.lock
generated
Normal file
7
13.Attributes/13 Attributes/Cargo.lock
generated
Normal file
@@ -0,0 +1,7 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "attributes"
|
||||
version = "0.1.0"
|
||||
8
13.Attributes/13 Attributes/Cargo.toml
Normal file
8
13.Attributes/13 Attributes/Cargo.toml
Normal file
@@ -0,0 +1,8 @@
|
||||
[package]
|
||||
name = "attributes"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
30
13.Attributes/13 Attributes/src/main.rs
Normal file
30
13.Attributes/13 Attributes/src/main.rs
Normal file
@@ -0,0 +1,30 @@
|
||||
//!
|
||||
//! 属性是一个元数据,可以使用在 模块、包、等等,这些元数据可以实现以下的功能
|
||||
//!
|
||||
//! - 条件编译
|
||||
//! - 设置包名称,版本和类型
|
||||
//! - 禁止语法检查和警告
|
||||
//! - 启用编译器的某些特性
|
||||
//! - 引用外部的库
|
||||
//! - 标记函数是单元测试
|
||||
//! - 标记函数是基准测试的一部分
|
||||
//! - 类似宏的属性
|
||||
//!
|
||||
//! 如果一个属性的生效范围是整个包(crate)的时候语法是 `#![crate_attribute]`,
|
||||
//! 如果只是指定的某个函数或模块等等的时候语法是 `#[item_attribute]`,没有 `!` 符号。
|
||||
//!
|
||||
//! 属性还可以接收参数,下面的几种语法都代表属性接收参数。
|
||||
//!
|
||||
//! - `#[attribute = "value"]`
|
||||
//! - `#[attribute(key = "value")]`
|
||||
//! - `#[attribute(value)]`
|
||||
//!
|
||||
//! 属性可以接收多个参数,如下所示
|
||||
//!
|
||||
//! - `#[attribute(value, value2)]`
|
||||
//! - `#[attribute(value, value2, value3
|
||||
//! value4, value5)]`
|
||||
//!
|
||||
fn main() {
|
||||
println!("Hello, world!");
|
||||
}
|
||||
Reference in New Issue
Block a user