2012-07-12 20:04:40 -05:00
|
|
|
trait connection {
|
|
|
|
fn read() -> int;
|
|
|
|
}
|
|
|
|
|
|
|
|
trait connection_factory<C: connection> {
|
|
|
|
fn create() -> C;
|
|
|
|
}
|
|
|
|
|
|
|
|
type my_connection = ();
|
|
|
|
type my_connection_factory = ();
|
|
|
|
|
2012-08-07 20:10:06 -05:00
|
|
|
impl (): connection {
|
2012-07-12 20:04:40 -05:00
|
|
|
fn read() -> int { 43 }
|
|
|
|
}
|
|
|
|
|
2012-08-07 20:10:06 -05:00
|
|
|
impl my_connection_factory: connection_factory<my_connection> {
|
2012-07-12 20:04:40 -05:00
|
|
|
fn create() -> my_connection { () }
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let factory = ();
|
|
|
|
let connection = factory.create();
|
|
|
|
let result = connection.read();
|
|
|
|
assert result == 43;
|
|
|
|
}
|