Skip to content

Instantly share code, notes, and snippets.

@octave99
Created June 24, 2019 15:53
Show Gist options
  • Save octave99/c2a81b4ae4539df4f9d69cc65705bcd2 to your computer and use it in GitHub Desktop.
Save octave99/c2a81b4ae4539df4f9d69cc65705bcd2 to your computer and use it in GitHub Desktop.
use std::fmt::{Debug, Formatter};
pub struct MyStruct<T> {
pub value: T,
}
impl<T> MyStruct<T> {
fn new(v: T) -> Self {
MyStruct { value: v }
}
}
impl Debug for MyStruct<u32> {
fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
write!(f, "{:?}\n", self.value)
}
}
impl Debug for MyStruct<&str> {
fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
write!(f, "{:?}\n", self.value)
}
}
fn main() {
let m = MyStruct::new(1);
let n = MyStruct::new("etst");
print!("{:?}", n);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment