We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent ec47b4f commit d71581eCopy full SHA for d71581e
src/main.rs
@@ -0,0 +1,31 @@
1
+use std::mem;
2
+
3
+trait Printable {
4
+ fn format(&self) -> String;
5
+}
6
7
+impl Printable for i32 {
8
+ fn format(&self) -> String {
9
+ format!("i32: {}", *self)
10
+ }
11
12
13
+impl Printable for String {
14
15
+ format!("string: {}", *self)
16
17
18
19
+fn print_it(z: &Printable) {
20
+ println!("{}", z.format());
21
22
23
+fn main() {
24
+ let a = 123;
25
+ let b = "hello".to_string();
26
27
+ // println!("{}", a.format());
28
+ // println!("{}", b.format());
29
+ print_it(a);
30
+ print_it(b);
31
0 commit comments