Crates.io | upget |
lib.rs | upget |
version | 0.1.1 |
source | src |
created_at | 2023-04-03 19:56:41.898472 |
updated_at | 2023-07-30 13:47:00.782889 |
description | Super simple trait that patterns the value "updae" and "get". |
homepage | |
repository | https://github.com/nossie531/upget |
max_upload_size | |
id | 829440 |
size | 15,541 |
Super simple trait that patterns the value "updae" and "get".
The author of this crate is not good at English.
Forgive me if the document is hard to read.
The Upget
trait only has an upget
method, which just updates self
value
with a closure and then retrieves it. That's all there is to it, but it allows
you to refactor common code patterns.
For example, the following code can be refactored...
fn clone_with_sort(vec: &Vec<String>) -> Vec<String> {
let mut result = vec.clone();
result.sort();
result
}
as follows.
fn clone_with_sort(vec: &Vec<String>) -> Vec<String> {
vec.clone().upget(|x| x.sort())
}
Such refactoring has the following benefits.
mut
specification.