pub trait UnaryOp<T>:
Sealed
+ Copy
+ 'staticwhere
T: NumericElement,{
// Required methods
unsafe fn apply<Arch>(
self,
v: <Arch as SimdKernel<T>>::Vector,
) -> <Arch as SimdKernel<T>>::Vector
where Arch: SimdKernel<T>;
fn apply_scalar(self, a: T) -> T;
}Expand description
Sealed ZST trait for single-operand SIMD elementwise operations.
Implementors define how a single vector is transformed (apply) and how
a single scalar element is transformed (apply_scalar). Both paths are
#[inline(always)] — DCE eliminates unused strategies entirely.
§Zero-Cost Guarantee
Every impl UnaryOp<T> passes through to an #[inline(always)] SimdKernel<T> method. The ZST strategy parameter is erased at every
monomorphization site: size_of::<Abs>() == 0.
Required Methods§
Sourceunsafe fn apply<Arch>(
self,
v: <Arch as SimdKernel<T>>::Vector,
) -> <Arch as SimdKernel<T>>::Vectorwhere
Arch: SimdKernel<T>,
unsafe fn apply<Arch>(
self,
v: <Arch as SimdKernel<T>>::Vector,
) -> <Arch as SimdKernel<T>>::Vectorwhere
Arch: SimdKernel<T>,
Apply the operation to a vector: self.apply::<Arch>(v) -> result.
Takes self by value so Clamp<T> can access its bounds; for true ZST
strategies (Abs, Neg, Sqrt), self has size zero and the compiler
removes it entirely from the generated code.
§Safety
Processor must support the target feature of Arch.
Sourcefn apply_scalar(self, a: T) -> T
fn apply_scalar(self, a: T) -> T
Apply the operation to a single scalar element.
Used for the SIMD tail (elements that do not fill a complete vector).
Requires only T: Scalar — no unsafe, no vector loads or stores.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".