Module wyz::pipe

source · []
Expand description

Pipe objects into functions, even those not available for dot-call.

Rust restricts the .method() call syntax to be available only on functions defined in impl [Trait for] Type blocks, with language-blessed self receivers.

This module allows any function to be .call()ed, with as little overhead as is possible in the language.

Examples

use wyz::pipe::*;

fn double(x: i32) -> i32 {
  x * 2
}

fn double_ref(x: &i32) -> i32 {
  *x * 2
}

assert_eq!(5.pipe(double), 10);
assert_eq!(5.pipe_ref(double_ref), 10);

Rust’s automatic de/reference chasing only works for the signatures Rust already permits in method-call syntax; the Pipe trait provides methods for certain reference conversion chasing, but cannot otherwise take advantage of the language builtin support for such behavior on ordinary methods.

Petition for a |> operator; sorry. !

Traits

Permit suffixed call of any function on a value.

Calls the AsRef or AsMut traits before piping.

Calls the Borrow or BorrowMut traits before piping.

Calls the Deref or DerefMut traits before piping.

Referential piping.