Skip to content

Instantly share code, notes, and snippets.

@Lakret
Created March 12, 2020 01:34
Show Gist options
  • Save Lakret/5359dfe317a7d6e62c2bd67a5103e588 to your computer and use it in GitHub Desktop.
Save Lakret/5359dfe317a7d6e62c2bd67a5103e588 to your computer and use it in GitHub Desktop.
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