3 releases

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

#464 in Programming languages

Download history 5466/week @ 2024-03-14 4861/week @ 2024-03-21 2970/week @ 2024-03-28 3933/week @ 2024-04-04 2863/week @ 2024-04-11 2835/week @ 2024-04-18 3509/week @ 2024-04-25 4295/week @ 2024-05-02 5152/week @ 2024-05-09 3816/week @ 2024-05-16 4095/week @ 2024-05-23 4468/week @ 2024-05-30 4797/week @ 2024-06-06 4120/week @ 2024-06-13 5964/week @ 2024-06-20 4639/week @ 2024-06-27

20,330 downloads per month
Used in 33 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