#运算符 #比较 #关系

later_operator

可解析、可存储、可打印的比较运算符,可选支持serde

6个版本

0.3.0 2024年7月29日
0.2.0 2024年2月8日
0.1.3 2023年10月5日
0.1.2 2023年6月1日
0.1.0 2023年2月10日

编码类别中排名第358

Download history 7/week @ 2024-06-29 5/week @ 2024-07-20 162/week @ 2024-07-27 5/week @ 2024-08-03

每月下载量172

WTFPL许可协议

20KB
328

Later Operator

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

此库提供了一个ComparisonOperator枚举,可以用于解析、存储、评估和/或打印Rust的关系运算符:!=<<===>=>

示例

use later_operator::ComparisonOperator;

// Parse from a string, then compare two arbitrary values.
let op = ComparisonOperator::try_from("<=").unwrap();
assert!(op.compare(&3_u8, &u8::MAX)); // 3 <= 255

// Re-stringify the operator for printing or whatever.
assert_eq!(
    format!("3 {op} 255"),
    "3 <= 255",
);

// Leading/trailing whitespace is ignored when parsing.
assert_eq!(
    ComparisonOperator::try_from("==").unwrap(),
    ComparisonOperator::try_from(" ==\n").unwrap(),
);

// But the value has to make sense or it will fail.
assert!(ComparisonOperator::try_from("~").is_err());

当可选的serde crate功能启用时,ComparisonOperator也可以作为字符串进行反序列化

use later_operator::ComparisonOperator;
use serde::{Deserialize, Serialize};

#[derive(Debug, Clone, Deserialize, Serialize)]
struct AffectedVersion {
    operator: ComparisonOperator,
    version: String,
}

安装

Cargo.toml中的dependencies部分添加later_operator,例如

[dependencies]
later_operator = "0.3.*"

许可协议

版权所有 © 2024 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.

依赖项

~170KB