Wrap

Trait Wrap 

Source
pub trait Wrap: Sized {
    // Provided methods
    fn wrap_ref<F>(self, wrap: F) -> Self
       where F: FnOnce(&Self) { ... }
    fn wrap_mut<F>(self, wrap: F) -> Self
       where F: FnOnce(&mut Self) { ... }
    fn wrap_map<F, R>(self, wrap: F) -> R
       where F: FnOnce(Self) -> R { ... }
}
Expand description

A trait that allows for creating ‘builder’ like chains of function calls.

This is a rough ‘open’ version of what StringExt and VecExt do, but is made for situations where theres no extension trait.

Provided Methods§

Source

fn wrap_ref<F>(self, wrap: F) -> Self
where F: FnOnce(&Self),

Turns a self reference function call into an ‘inline’/‘builder’ call.

This function normally isn’t needed, if you need to access a value you can use Peep. Theres normally something wrong with the library if you need to use this.

Source

fn wrap_mut<F>(self, wrap: F) -> Self
where F: FnOnce(&mut Self),

Turns a self mutable reference function call into an ‘inline’/‘builder’ call.

§Examples

If you didn’t want to use VecExt for some reason you could do this.

use fenn::Wrap;

let ex = vec![1, 1, 3, 5, 5, 5, 7].wrap_mut(Vec::dedup);

assert_eq!(vec![1, 3, 5, 7], ex);
Source

fn wrap_map<F, R>(self, wrap: F) -> R
where F: FnOnce(Self) -> R,

Turns a consuming function call into an ‘inline’/‘builder’ call.

§Examples
use fenn::Wrap;

let ex = 4.wrap_map(|n| n * 2);

assert_eq!(8, ex);

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<T> Wrap for T