3 releases

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

#386 in Programming languages

Download history 3532/week @ 2024-11-16 3903/week @ 2024-11-23 4849/week @ 2024-11-30 4459/week @ 2024-12-07 4411/week @ 2024-12-14 2359/week @ 2024-12-21 2520/week @ 2024-12-28 5079/week @ 2025-01-04 4847/week @ 2025-01-11 4873/week @ 2025-01-18 4361/week @ 2025-01-25 5805/week @ 2025-02-01 6256/week @ 2025-02-08 7125/week @ 2025-02-15 7090/week @ 2025-02-22 8471/week @ 2025-03-01

29,888 downloads per month
Used in 61 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

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