Documentation
  • Coverage
  • 85.71%
    6 out of 7 items documented1 out of 6 items with examples
  • Size
  • Source code size: 6.61 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 269.73 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Links
  • sarah-quinones/coe-rs
    2 1 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • sarah-quinones

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