1 stable release
Uses old Rust 2015
1.0.0 | Jul 28, 2017 |
---|
#1242 in Programming languages
3KB
rust-typed
lib.rs
:
typed
Type annotation to help rustc. This is useful for code generation.
Usage
This does not work without ufcs, because it's ambiguous.
trait ChangeWatcher<T> {
fn is_changed(&self) -> bool;
}
struct DbConfig;
struct AppConfig;
struct Context;
impl ChangeWatcher<DbConfig> for Context {
fn is_changed(&self) -> bool { false }
}
impl ChangeWatcher<AppConfig> for Context {
fn is_changed(&self) -> bool { false }
}
fn some<C: ChangeWatcher<DbConfig> + ChangeWatcher<AppConfig>>(c: C) {
if <C as ChangeWatcher<DbConfig>>::is_changed(&c) {
}
}
But this works.
extern crate typed;
use typed::{Type, type_of};
trait ChangeWatcher<T> {
fn is_changed(&self, _: Type<T>) -> bool;
}
struct DbConfig;
struct AppConfig;
struct Context;
impl ChangeWatcher<DbConfig> for Context {
fn is_changed(&self, _: Type<DbConfig>) -> bool { false }
}
impl ChangeWatcher<AppConfig> for Context {
fn is_changed(&self, _: Type<AppConfig>) -> bool { false }
}
fn some<C: ChangeWatcher<DbConfig> + ChangeWatcher<AppConfig>>(c: C) {
if c.is_changed(type_of::<DbConfig>()) {
}
}