3 releases

0.1.2 Mar 20, 2023
0.1.1 Mar 20, 2023
0.1.0 Mar 20, 2023

#586 in Hardware support

Download history 4414/week @ 2024-08-12 5486/week @ 2024-08-19 5366/week @ 2024-08-26 6244/week @ 2024-09-02 5765/week @ 2024-09-09 5291/week @ 2024-09-16 4300/week @ 2024-09-23 3905/week @ 2024-09-30 3666/week @ 2024-10-07 3411/week @ 2024-10-14 3821/week @ 2024-10-21 4279/week @ 2024-10-28 5835/week @ 2024-11-04 3264/week @ 2024-11-11 3625/week @ 2024-11-18 3992/week @ 2024-11-25

16,946 downloads per month
Used in 53 crates (12 directly)

MIT license

6KB
84 lines

Documentation Crate

coe-rs is a Rust library for coercing a value of a given type into the same type, in cases where the compiler can't prove the two types are equal.
This can be used to emulate specialization in to a limited extent.

Example

use coe::{Coerce, is_same};
use core::ops::Add;
fn foo<T: 'static + Copy + Add<Output = T>>(slice: &mut [T]) {
    if is_same::<f64, T>() {
        // use some optimized SIMD implementation
        // ...
        println!("using SIMD operations");
        let slice: &mut [f64] = slice.coerce();
    } else {
        for value in slice {
            println!("using fallback implementation");
            *value = *value + *value;
        }
    }
}
foo(&mut [1, 2, 3u64]); // calls fallback implementation
foo(&mut [1.0, 2.0, 3.0f64]); // calls SIMD implementation

lib.rs:

coe-rs is a Rust library for coercing a value of a given type into the same type, in cases where the compiler can't prove the two types are equal.
This can be used to emulate specialization in to a limited extent.

No runtime deps