ufcs

Crates.ioufcs
lib.rsufcs
version0.1.0
sourcesrc
created_at2019-12-10 19:40:04.822866
updated_at2019-12-10 19:40:04.822866
descriptionHelper trait to call free functions using method call syntax
homepage
repositoryhttps://github.com/xzfc/ufcs.rs
max_upload_size
id188291
size7,141
(xzfc)

documentation

README

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

Commit count: 2

cargo fmt