3 releases

Uses old Rust 2015

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

#1916 in Rust patterns

35 downloads per month

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