This commit is contained in:
nap.liu
2023-12-11 18:40:53 +08:00
parent d1b95f1096
commit 5dc4708fe2
79 changed files with 2269 additions and 39 deletions

7
13.Attributes/13 Attributes/Cargo.lock generated Normal file
View 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"

View 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]

View 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!");
}