#output #structured #line #cli #instance #arguments #printed

structured-output

一个结构化CLI输出的库,可以以打印行或JSON的形式显示

2个版本

0.1.1 2023年5月10日
0.1.0 2023年5月10日

#5 in #printed

Download history • Rust 包仓库 14/week @ 2024-04-07 • Rust 包仓库 17/week @ 2024-04-14 • Rust 包仓库 22/week @ 2024-04-21 • Rust 包仓库 27/week @ 2024-04-28 • Rust 包仓库 14/week @ 2024-05-05 • Rust 包仓库 23/week @ 2024-05-12 • Rust 包仓库 22/week @ 2024-05-19 • Rust 包仓库 21/week @ 2024-05-26 • Rust 包仓库 15/week @ 2024-06-02 • Rust 包仓库 11/week @ 2024-06-09 • Rust 包仓库 110/week @ 2024-06-16 • Rust 包仓库 82/week @ 2024-06-23 • Rust 包仓库 7/week @ 2024-06-30 • Rust 包仓库 3/week @ 2024-07-07 • Rust 包仓库 31/week @ 2024-07-14 • Rust 包仓库 40/week @ 2024-07-21 • Rust 包仓库

81 每月下载
用于 8 crates

Apache-2.0

5KB

structured-output Rust包

StructuredOutput是一个Rust库,提供了一种结构来处理带有字符串和JSON值的结构化输出。

安装

要在Rust项目中使用此库,请将以下内容添加到您的Cargo.toml文件中

[dependencies]
structured_output = "0.1.0"

使用

您可以使用new方法创建一个新的StructuredOutput实例,该方法接受一个字符串和一个JSON值作为参数

let lines = "Hello world!";
let json = serde_json::json!({ "message": lines });
let output = StructuredOutput::new(lines, json.clone());

您可以使用linesjson方法分别检索字符串和JSON值

assert_eq!(output.lines(), "Hello world!");
assert_eq!(output.json(), &json);

您还可以使用to_json_stringto_json_pretty方法将JSON值获取为JSON字符串或格式化好的JSON字符串

assert_eq!(output.to_json_string(), "{\"message\":\"Hello world!\"}");
assert_eq!(output.to_json_pretty(), "{\n  \"message\": \"Hello world!\"\n}");

StructuredOutputDisplay实现默认为字符串值。您可以使用println!宏直接打印字符串值

println!("{}", output);

许可协议

此库根据Apache 2.0许可协议授权。

依赖项

~0.7–1.6MB
~35K SLoC