This trait requires `fmt` with this exact signature.
(&self, f: &mut std::fmt::Formatter)
| 115 | impl std::fmt::Display for Point2D { |
| 116 | // This trait requires `fmt` with this exact signature. |
| 117 | fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { |
| 118 | // Write strictly the first element into the supplied output |
| 119 | // stream: `f`. Returns `fmt::Result` which indicates whether the |
| 120 | // operation succeeded or failed. Note that `write!` uses syntax which |
| 121 | // is very similar to `println!`. |
| 122 | // write!(f, "x: {}, y: {}", self.x, self.y) // If it was a tupple, we could access if like self.0, self.1 |
| 123 | |
| 124 | // Rust provides the ? operator, which can be combined with write! for complex writes |
| 125 | // Try `write!` to see if it errors. If it errors, return the error. Otherwise continue. |
| 126 | // As an example (This is the equivalent solution from the above): |
| 127 | // Use this trick for more complex structures that need to break in steps the print sequence |
| 128 | write!(f, "x: {}", self.x)?; |
| 129 | write!(f, ", y: {}", self.y) |
| 130 | } |
| 131 | } |
| 132 | |
| 133 | let point = Point2D { x: 3.3, y: 7.2 }; |
nothing calls this directly
no outgoing calls
no test coverage detected