3 releases

Uses old Rust 2015

0.0.3 Apr 7, 2016
0.0.2 Apr 7, 2016
0.0.1 Apr 6, 2016

#2831 in Rust patterns

Download history 5/week @ 2024-09-18 28/week @ 2024-09-25 43/week @ 2024-10-02 117/week @ 2024-10-09 8/week @ 2024-10-16 5/week @ 2024-10-23 1/week @ 2024-10-30

134 downloads per month
Used in try-specialize

MIT license

23KB
473 lines

specialize-rs

travis-badge release-badge docs-badge license-badge

specialize is an experimental Rust library for working with type specialization.

Documentation

See the documentation for all provided macros and types, and more up-to-date syntax and information.

Constrain

The constrain!() macro can be used to add additional type bounds to an existing generic parameter. For example, imagine you want to print out the debug representation of a type without adding it to your generic bounds:

#[macro_use]
extern crate specialize;

fn some_func<T: SomeTrait>(t: &T) {
    if let Some(debug) = constrain!(ref [t: Debug] = ()) {
        println!("some_func({:?})", debug);
    }
    t.something();
}

It can also be used as a replacement for Any, allowing a generic type to become its matching concrete type again.

Specialize

The specialize! { } macro allows for more advanced matching of types, but is more cumbersome due to its syntax and implementation of an external function. See the documentation for more details.

No runtime deps