upget 0.2.1

Super simple trait that patterns the value "updae" and "get".
Documentation
  • Coverage
  • 100%
    4 out of 4 items documented2 out of 3 items with examples
  • Size
  • Source code size: 15.87 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 561.08 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 12s Average build duration of successful builds.
  • all releases: 9s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • nossie531/upget
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • nossie531

upget

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.

Target Code

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.

  • Simplification of code.
  • Elimination of intermediate variables.
  • Elimination of the mut specification.

Versions

See CHANGELOG.