3 releases

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

#426 in Programming languages

Download history 420/week @ 2024-01-05 594/week @ 2024-01-12 561/week @ 2024-01-19 1955/week @ 2024-01-26 1927/week @ 2024-02-02 2760/week @ 2024-02-09 2723/week @ 2024-02-16 2678/week @ 2024-02-23 2849/week @ 2024-03-01 3459/week @ 2024-03-08 6029/week @ 2024-03-15 4065/week @ 2024-03-22 3481/week @ 2024-03-29 3277/week @ 2024-04-05 2900/week @ 2024-04-12 2417/week @ 2024-04-19

12,592 downloads per month
Used in 28 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