3 releases

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

#422 in Programming languages

Download history 651/week @ 2023-12-05 961/week @ 2023-12-12 661/week @ 2023-12-19 652/week @ 2023-12-26 462/week @ 2024-01-02 475/week @ 2024-01-09 568/week @ 2024-01-16 606/week @ 2024-01-23 2432/week @ 2024-01-30 2262/week @ 2024-02-06 3036/week @ 2024-02-13 2571/week @ 2024-02-20 2934/week @ 2024-02-27 2561/week @ 2024-03-05 4894/week @ 2024-03-12 5264/week @ 2024-03-19

16,162 downloads per month
Used in 26 crates (9 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