Last active
August 29, 2015 14:21
-
-
Save kmizu/b66a0180de6247a4ac8a 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; | |
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); | |
} |
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
>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