Crates.io | specialize |
lib.rs | specialize |
version | 0.0.3 |
source | src |
created_at | 2016-04-06 22:13:33.285041 |
updated_at | 2016-04-07 21:54:13.407764 |
description | Type specialization macros and helpers. |
homepage | |
repository | https://github.com/arcnmx/specialize-rs |
max_upload_size | |
id | 4689 |
size | 24,278 |
specialize
is an experimental Rust library for working with type specialization.
See the documentation for all provided macros and types, and more up-to-date syntax and information.
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.
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.