ufcs 0.1.0

Helper trait to call free functions using method call syntax
Documentation
  • Coverage
  • 0%
    0 out of 3 items documented0 out of 2 items with examples
  • Size
  • Source code size: 7.14 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 449.49 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 9s Average build duration of successful builds.
  • all releases: 9s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • xzfc/ufcs.rs
    2 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • xzfc

ufcs.rs

Crates.io License Build Status

ufcs::Pipe — helper trait to call free functions using method call syntax.

Rust already allows calling methods using function call syntax, but not the other way around. This crate fills the gap by providing a simple helper trait Pipe.

Usage

Cargo.toml:

[dependencies]
ufcs = "0.1.0"

Rust code:

use ufcs::Pipe;

Examples

// Write this
foo().pipe(bar).pipe(baz);

// Instead of this
baz(bar(foo()));
// Write this
let text: String = reqwest::get("http://httpbin.org/get")
    .await?
    .json::<serde_json::Value>()
    .await?
    .pipe(toml::Value::try_from)?
    .pipe(|x| toml::to_string(&x))?;

// Instead of this
let text: String = toml::to_string(&toml::Value::try_from(
    reqwest::get("http://httpbin.org/get")
        .await?
        .json::<serde_json::Value>()
        .await?,
)?)?;

See tests for more examples.

See also

Roughtly the same feature is either implemented or proposed in various languages.

Rust

Other languages