Skip to content

Instantly share code, notes, and snippets.

@rust-play
Created November 25, 2021 12:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rust-play/2c4f7a18f3896089c2bf4e53834dd5e1 to your computer and use it in GitHub Desktop.
Save rust-play/2c4f7a18f3896089c2bf4e53834dd5e1 to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
struct Abc<T> {
name: String,
value: T,
}
impl<T> std::fmt::Debug for Abc<T> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "Abc({})", self.name)
}
}
#[derive(Debug)]
enum Item<T> {
Alpha,
Beta(Abc<T>)
}
struct Xyz {
value: i32,
}
fn main() {
let abc = Abc {
name: "abc".to_string(),
value: Xyz { value: 1 },
};
println!("{:?}", abc);
let item = Item::Beta(abc);
println!("{:?}", item);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment