newtype
This commit is contained in:
13
src/main.rs
13
src/main.rs
@@ -99,6 +99,14 @@ impl fmt::Display for Point {
|
||||
|
||||
impl OutlinePrint for Point {}
|
||||
|
||||
struct Wrapper(Vec<String>);
|
||||
|
||||
impl fmt::Display for Wrapper {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "[{}]", self.0.join(", "))
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
assert_eq!(
|
||||
Point { x: 1, y: 0 } + Point { x: 2, y: 3 },
|
||||
@@ -119,5 +127,8 @@ fn main() {
|
||||
|
||||
let xy = Point { x: 344, y: 576 };
|
||||
xy.outline_print();
|
||||
println!("{}", Point {x: 34, y:45})
|
||||
println!("{}", Point {x: 34, y:45});
|
||||
|
||||
let w = Wrapper(vec![String::from("hello"), String::from("world")]);
|
||||
println!("w = {}", w);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user