Created
March 12, 2020 01:34
-
-
Save Lakret/5359dfe317a7d6e62c2bd67a5103e588 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::fmt; | |
use std::fmt::{Display, Formatter}; | |
struct S { | |
x: i64, | |
} | |
fn define_impl() { | |
impl Display for S { | |
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { | |
write!(f, "S {}", self.x) | |
} | |
} | |
} | |
fn main() { | |
// function call is not required to bring the defined trait implementation into the scope! | |
let s = S { x: -298 }; | |
println!("s = {}", s); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment