mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-27 01:04:03 +00:00
test: Add a max/min classes test case
This commit is contained in:
parent
728d16cfca
commit
22ef08293e
30
src/test/run-pass/max-min-classes.rs
Normal file
30
src/test/run-pass/max-min-classes.rs
Normal file
@ -0,0 +1,30 @@
|
||||
trait Product {
|
||||
fn product() -> int;
|
||||
}
|
||||
|
||||
struct Foo {
|
||||
x: int;
|
||||
y: int;
|
||||
}
|
||||
|
||||
impl Foo {
|
||||
fn sum() -> int {
|
||||
self.x + self.y
|
||||
}
|
||||
}
|
||||
|
||||
impl Foo : Product {
|
||||
fn product() -> int {
|
||||
self.x * self.y
|
||||
}
|
||||
}
|
||||
|
||||
fn Foo(x: int, y: int) -> Foo {
|
||||
Foo { x: x, y: y }
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let foo = Foo(3, 20);
|
||||
io::println(#fmt("%d %d", foo.sum(), foo.product()));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user