feat(wpcarro/rust): Include std::fmt::Display example
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
This commit is contained in:
parent
783e1190cd
commit
4732603a42
6 changed files with 123 additions and 50 deletions
13
users/wpcarro/scratch/rust/src/display/mod.rs
Normal file
13
users/wpcarro/scratch/rust/src/display/mod.rs
Normal file
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue