2014-02-07 20:08:32 +01:00
|
|
|
// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
|
2013-01-10 15:15:24 -08:00
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
|
|
|
struct Point {
|
2013-09-26 02:26:09 -04:00
|
|
|
x: f64,
|
|
|
|
y: f64,
|
2013-01-10 15:15:24 -08:00
|
|
|
}
|
|
|
|
|
2014-06-21 03:39:03 -07:00
|
|
|
trait ToString_ {
|
|
|
|
fn to_string(&self) -> String;
|
2014-06-18 14:16:45 +01:00
|
|
|
}
|
|
|
|
|
2014-06-21 03:39:03 -07:00
|
|
|
impl ToString_ for Point {
|
2013-09-26 02:26:09 -04:00
|
|
|
fn new(x: f64, y: f64) -> Point {
|
2014-06-21 03:39:03 -07:00
|
|
|
//~^ ERROR method `new` is not a member of trait `ToString_`
|
2013-01-10 15:15:24 -08:00
|
|
|
Point { x: x, y: y }
|
|
|
|
}
|
|
|
|
|
2014-06-21 03:39:03 -07:00
|
|
|
fn to_string(&self) -> String {
|
2014-02-21 15:41:51 -08:00
|
|
|
format!("({}, {})", self.x, self.y)
|
2013-01-10 15:15:24 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
2014-02-21 15:41:51 -08:00
|
|
|
let p = Point::new(0.0, 0.0);
|
2015-12-11 20:59:11 +13:00
|
|
|
//~^ ERROR no associated item named `new` found for type `Point` in the current scope
|
2016-01-08 20:16:30 -05:00
|
|
|
println!("{}", p.to_string()); //~ ERROR type of this value must be known
|
2013-01-10 15:15:24 -08:00
|
|
|
}
|