状态
当前可运行:
| API | 返回值 | 说明 |
|---|---|---|
std.args.len() | usize | 返回进程参数数量。 |
std.args.get(index) | Maybe<String> | 当存在时返回 index 处的参数。 |
当前限制:
- 迭代器风格的参数 API。
- 类型化解码辅助工具。
- 针对无进程参数平台的诊断信息。
示例
pub fn main Void world World ! let count std.args.len() let first std.args.get 1 if && (> count 1) first.has check world.out.write first.value check world.out.write "\n"设计说明
该模块仅适用于宿主环境。独立、边缘和嵌入式目标应拒绝使用,除非它们显式提供参数能力。
在原生 Windows 风格目标上,std.args 是面向字节的进程输入,而非 Unicode argv 规范化层。
需要可移植参数语义的程序应将目标特定的解码逻辑放在目标无关的核心代码之外。