3 releases

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

#573 in Hardware support

Download history 5011/week @ 2024-07-21 5751/week @ 2024-07-28 4147/week @ 2024-08-04 4434/week @ 2024-08-11 5256/week @ 2024-08-18 5402/week @ 2024-08-25 6162/week @ 2024-09-01 6059/week @ 2024-09-08 5325/week @ 2024-09-15 4208/week @ 2024-09-22 3958/week @ 2024-09-29 3715/week @ 2024-10-06 3219/week @ 2024-10-13 3811/week @ 2024-10-20 4379/week @ 2024-10-27 5817/week @ 2024-11-03

17,606 downloads per month
Used in 51 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