1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
use std::fmt::{Show,Formatter,FormatError}; struct Point { x: int, y: int, } impl Show for Point { fn fmt (&self, f: &mut Formatter) -> Result<(), FormatError> { try!(write!(f, "({}, {})", self.x, self.y)); return Ok(()); } } fn main () { let p1 = Point { x: 1, y: 2 }; println!("{}", p1); }