3 releases

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

#432 in Programming languages

Download history 2343/week @ 2024-12-25 3629/week @ 2025-01-01 4803/week @ 2025-01-08 5126/week @ 2025-01-15 4613/week @ 2025-01-22 4369/week @ 2025-01-29 6746/week @ 2025-02-05 6140/week @ 2025-02-12 7336/week @ 2025-02-19 8083/week @ 2025-02-26 7200/week @ 2025-03-05 7354/week @ 2025-03-12 8528/week @ 2025-03-19 7864/week @ 2025-03-26 7556/week @ 2025-04-02 4238/week @ 2025-04-09

29,829 downloads per month
Used in 57 crates (11 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

No runtime deps