2019-07-27 00:54:25 +03:00
|
|
|
// run-pass
|
|
|
|
|
2018-09-14 12:20:28 +02:00
|
|
|
#![allow(non_snake_case)]
|
2012-07-24 16:39:26 -07:00
|
|
|
trait Product {
|
2015-03-25 17:06:52 -07:00
|
|
|
fn product(&self) -> isize;
|
2012-07-24 16:39:26 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
struct Foo {
|
2015-03-25 17:06:52 -07:00
|
|
|
x: isize,
|
|
|
|
y: isize,
|
2012-07-24 16:39:26 -07:00
|
|
|
}
|
|
|
|
|
2013-05-31 15:17:22 -07:00
|
|
|
impl Foo {
|
2015-03-25 17:06:52 -07:00
|
|
|
pub fn sum(&self) -> isize {
|
2012-07-24 16:39:26 -07:00
|
|
|
self.x + self.y
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-14 11:47:00 -08:00
|
|
|
impl Product for Foo {
|
2015-03-25 17:06:52 -07:00
|
|
|
fn product(&self) -> isize {
|
2012-07-24 16:39:26 -07:00
|
|
|
self.x * self.y
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-25 17:06:52 -07:00
|
|
|
fn Foo(x: isize, y: isize) -> Foo {
|
2012-07-24 16:39:26 -07:00
|
|
|
Foo { x: x, y: y }
|
|
|
|
}
|
|
|
|
|
2013-02-01 19:43:17 -08:00
|
|
|
pub fn main() {
|
2012-07-24 16:39:26 -07:00
|
|
|
let foo = Foo(3, 20);
|
2013-09-24 22:16:43 -07:00
|
|
|
println!("{} {}", foo.sum(), foo.product());
|
2012-07-24 16:39:26 -07:00
|
|
|
}
|