Crates.io | ufcs |
lib.rs | ufcs |
version | 0.1.0 |
source | src |
created_at | 2019-12-10 19:40:04.822866 |
updated_at | 2019-12-10 19:40:04.822866 |
description | Helper trait to call free functions using method call syntax |
homepage | |
repository | https://github.com/xzfc/ufcs.rs |
max_upload_size | |
id | 188291 |
size | 7,141 |
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
.
Cargo.toml:
[dependencies]
ufcs = "0.1.0"
Rust code:
use ufcs::Pipe;
// 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.
Roughtly the same feature is either implemented or proposed in various languages.
pipeline.rs
: implemented as an macroarbitrary_self_types
|>