about summary refs log tree commit diff
path: root/users/wpcarro/scratch/rust/src/display/mod.rs
diff options
context:
space:
mode:
authorWilliam Carroll <wpcarro@gmail.com>2022-08-09T17·20-0700
committerclbot <clbot@tvl.fyi>2022-08-09T17·22+0000
commit4732603a42c76ea53ab6a4d7358380f4d0194c48 (patch)
tree97d79231f08d99dd89cae79d799c6c48bd5b1bd6 /users/wpcarro/scratch/rust/src/display/mod.rs
parent783e1190cdbc1a5fe60f5c5cc1dc3a9861ee138f (diff)
feat(wpcarro/rust): Include std::fmt::Display example r/4396
Gotta know how to `to_string` things

Change-Id: I259ef61ecaf6ae7fabe0b3d211706ba5f429b3a7
Reviewed-on: https://cl.tvl.fyi/c/depot/+/6057
Reviewed-by: wpcarro <wpcarro@gmail.com>
Autosubmit: wpcarro <wpcarro@gmail.com>
Tested-by: BuildkiteCI
Diffstat (limited to 'users/wpcarro/scratch/rust/src/display/mod.rs')
-rw-r--r--users/wpcarro/scratch/rust/src/display/mod.rs13
1 files changed, 13 insertions, 0 deletions
diff --git a/users/wpcarro/scratch/rust/src/display/mod.rs b/users/wpcarro/scratch/rust/src/display/mod.rs
new file mode 100644
index 000000000000..838463109190
--- /dev/null
+++ b/users/wpcarro/scratch/rust/src/display/mod.rs
@@ -0,0 +1,13 @@
+use std::fmt;
+
+pub struct Person {
+    pub fname: String,
+    pub lname: String,
+    pub age: i8,
+}
+
+impl fmt::Display for Person {
+    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+        write!(f, "{}, {} ({} years old)", self.lname, self.fname, self.age)
+    }
+}