Created
June 24, 2019 15:53
-
-
Save octave99/c2a81b4ae4539df4f9d69cc65705bcd2 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::{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