UnaryOperatorOnce

Trait UnaryOperatorOnce 

Source
pub trait UnaryOperatorOnce<T>: TransformerOnce<T, T> { }
Expand description

UnaryOperatorOnce trait - marker trait for one-time use unary operators

A one-time use unary operator transforms a value of type T to another value of the same type T, consuming self in the process. This trait extends TransformerOnce<T, T> to provide semantic clarity for same-type transformations with consuming semantics. Equivalent to Java’s UnaryOperator<T> but with FnOnce semantics.

§Automatic Implementation

This trait is automatically implemented for all types that implement TransformerOnce<T, T>, so you don’t need to implement it manually.

§Type Parameters

  • T - The type of both input and output values

§Examples

§Using in generic constraints

use prism3_function::{UnaryOperatorOnce, TransformerOnce};

fn apply_once<T, O>(value: T, op: O) -> T
where
    O: UnaryOperatorOnce<T>,
{
    op.apply_once(value)
}

let double = |x: i32| x * 2;
assert_eq!(apply_once(21, double), 42);

§Author

Hu Haixing

Implementors§

Source§

impl<F, T> UnaryOperatorOnce<T> for F
where F: TransformerOnce<T, T>, T: 'static,

Blanket implementation of UnaryOperatorOnce for all TransformerOnce<T, T>

This automatically implements UnaryOperatorOnce<T> for any type that implements TransformerOnce<T, T>.

§Author

Hu Haixing