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