Skip to content

Instantly share code, notes, and snippets.

@kmizu
Last active August 29, 2015 14:21
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 kmizu/b66a0180de6247a4ac8a to your computer and use it in GitHub Desktop.
Save kmizu/b66a0180de6247a4ac8a to your computer and use it in GitHub Desktop.
use std::fmt;
use List::{Cons, Nil};
enum List<T> {
Cons(T, Box<List<T>>),
Nil
}
impl<T> fmt::Display for List<T> where T : fmt::Display {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
Cons(ref head, ref tail) =>
{
write!(f, "{head} ::", head = head);
write!(f, "{tail}", tail = tail)
}
Nil => write!(f, "Nil")
}
}
}
fn main() {
let list = Cons("A", Box::new(Cons("B", Box::new(Cons("C", Box::new(Nil))))));
println!("Hello, {rust}", rust=list);
}
>rustc list.rs
<std macros>:2:1: 2:54 warning: unused result which must be used, #[warn(unused_
<std macros>:2 $ dst . write_fmt ( format_args ! ( $ ( $ arg ) * ) ) )
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<std macros>:1:1: 2:56 note: in expansion of write!
list.rs:15:11: 15:47 note: expansion site
>list
Hello, A ::B ::C ::Nil
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment