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: toml [dependencies] ufcs = "0.1.0"

Rust code: rust use ufcs::Pipe;

Examples

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

// Instead of this baz(bar(foo())); ```

```rust // Write this let text: String = reqwest::get("http://httpbin.org/get") .await? .json::() .await? .pipe(toml::Value::tryfrom)? .pipe(|x| toml::tostring(&x))?;

// Instead of this let text: String = toml::tostring(&toml::Value::tryfrom( reqwest::get("http://httpbin.org/get") .await? .json::() .await?, )?)?; ```

See tests for more examples.

See also

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

Rust

Other languages