#string #join #list #grammar

no-std oxford_join

用牛津逗号连接字符串切片!

12个版本

0.2.9 2023年10月5日
0.2.8 2023年6月1日
0.2.7 2023年1月26日
0.2.6 2022年12月27日
0.1.1 2021年6月27日

#256文本处理

Download history 9/week @ 2024-04-13 10/week @ 2024-05-18 5/week @ 2024-05-25 4/week @ 2024-06-08 1/week @ 2024-06-15 1/week @ 2024-06-22 69/week @ 2024-07-27

69 每月下载量
guff_css 中使用

WTFPL 许可证

24KB
379

牛津连接

docs.rs changelog
crates.io ci deps.rs
license contributions welcome

使用您选择的连接词以插入必要的牛津逗号连接字符串切片。

(就像它应该那样。哈哈。)

返回格式化取决于集合的大小

0: ""
1: "first"
2: "first <CONJUNCTION> last"
n: "first, second, …, <CONJUNCTION> last"

此crate与#![no_std]兼容。

示例

这个魔法是通过OxfordJoin trait完成的。导入它,大多数持有AsRef<str>的切片式东西都将继承OxfordJoin::oxford_join方法以进行连接。

use oxford_join::{Conjunction, OxfordJoin};

let set = ["Apples", "Oranges"];
assert_eq!(set.oxford_join(Conjunction::And), "Apples and Oranges");

let set = ["Apples", "Oranges", "Bananas"];
assert_eq!(set.oxford_join(Conjunction::And), "Apples, Oranges, and Bananas");

// There are also shorthand methods for and, or, and_or, and nor, allowing you
// to skip the Conjunction enum entirely.
assert_eq!(set.oxford_and(), "Apples, Oranges, and Bananas");
assert_eq!(set.oxford_and_or(), "Apples, Oranges, and/or Bananas");
assert_eq!(set.oxford_nor(), "Apples, Oranges, nor Bananas");
assert_eq!(set.oxford_or(), "Apples, Oranges, or Bananas");

就是这样,朋友们!

安装

oxford_join添加到您的Cargo.toml中的dependencies,如下所示

[dependencies]
oxford_join = "0.2.*"

许可证

版权所有 © 2023 Blobfolio, LLC <[email protected]>

本作品是免费的。您可以在Do What The Fuck You Want To Public License,版本2的条款下重新分发或修改它。

DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004

Copyright (C) 2004 Sam Hocevar <sam@hocevar.net>

Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.

DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION

0. You just DO WHAT THE FUCK YOU WANT TO.

无运行时依赖