2013-01-10 17:15:24 -06:00
|
|
|
struct Point {
|
2013-09-26 01:26:09 -05:00
|
|
|
x: f64,
|
|
|
|
y: f64,
|
2013-01-10 17:15:24 -06:00
|
|
|
}
|
|
|
|
|
2014-06-21 05:39:03 -05:00
|
|
|
trait ToString_ {
|
|
|
|
fn to_string(&self) -> String;
|
2014-06-18 08:16:45 -05:00
|
|
|
}
|
|
|
|
|
2014-06-21 05:39:03 -05:00
|
|
|
impl ToString_ for Point {
|
2013-09-26 01:26:09 -05:00
|
|
|
fn new(x: f64, y: f64) -> Point {
|
2014-06-21 05:39:03 -05:00
|
|
|
//~^ ERROR method `new` is not a member of trait `ToString_`
|
2013-01-10 17:15:24 -06:00
|
|
|
Point { x: x, y: y }
|
|
|
|
}
|
|
|
|
|
2014-06-21 05:39:03 -05:00
|
|
|
fn to_string(&self) -> String {
|
2014-02-21 17:41:51 -06:00
|
|
|
format!("({}, {})", self.x, self.y)
|
2013-01-10 17:15:24 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
2014-02-21 17:41:51 -06:00
|
|
|
let p = Point::new(0.0, 0.0);
|
2020-01-08 10:05:31 -06:00
|
|
|
//~^ ERROR no function or associated item named `new` found for struct `Point`
|
2016-04-12 11:19:13 -05:00
|
|
|
println!("{}", p.to_string());
|
2013-01-10 17:15:24 -06:00
|
|
|
}
|