Crates.io | gan |
lib.rs | gan |
version | 0.1.2 |
created_at | 2025-02-26 08:46:29.581022+00 |
updated_at | 2025-02-26 10:46:45.361922+00 |
description | Just do it! A small tool provides ergonomic value handling with ignore/ ok/ some semantics. |
homepage | https://github.com/muyuanjin/gan |
repository | https://github.com/muyuanjin/gan |
max_upload_size | |
id | 1570142 |
size | 11,216 |
帮助开发者更果決地处理返回值的实用库。提供符合人体工程学的快捷方法来忽略结果/快速构造默认值。 A pragmatic Rust library that helps developers handle return values decisively. Provides ergonomic methods to ignore results or construct default values with semantic shortcuts.
在 Cargo.toml
添加(Add to your Cargo.toml):
[dependencies]
gan = "0.1"
操作 | 表达式示例 | 返回类型 | 示例用途 |
---|---|---|---|
忽略结果 | expr.ignore() |
() |
format!("{}", 42).ignore(); |
构造 Ok 单元 | expr.ok() |
Result<(), E> |
write!(file, "{}", data)?.ok() |
构造 Ok 单元 | result.ignore().ok() |
Result<(), E> |
write!(file, "{}", data).ignore().ok() |
构造 Ok 包裹 | expr.okay() |
Result<T, E> |
42.okay() |
构造 Some 值 | expr.some() |
Option<T> |
42.some() |
构造 None 值 | expr.none() |
Option<U> |
42.none() |
Operation | Expression Example | Return Type | Example Use Case |
---|---|---|---|
Ignore Result | expr.ignore() |
() |
format!("{}", 42).ignore(); |
Construct Ok Unit | expr.ok() |
Result<(), E> |
write!(file, "{}", data)?.ok() |
Construct Ok Unit | result.ignore().ok() |
Result<(), E> |
write!(file, "{}", data).ignore().ok() |
Construct Ok Wrapped | expr.okay() |
Result<T, E> |
42.okay() |
Construct Some Value | expr.some() |
Option<T> |
42.some() |
Construct None Value | expr.none() |
Option<U> |
42.none() |
MIT License © 2024 允许商业使用/修改/分发,无担保责任 Permits commercial use/modification/distribution with no warranty