extern crate syn;

use std::env;
use std::fs::{File, create_dir};
use std::io::{Write, BufWriter};
use syn::DeriveInput;

pub fn generate_elm(ast: &DeriveInput) {
    let mut path = env::current_dir().unwrap();
    path.push("generated");
    if path.exists() && path.is_file() { panic!("expecting \"generated\" to be a directory"); }
    if !path.exists() { create_dir(path.clone()).expect("problem creating \"generated\" directory") }
    let name = &ast.ident;
    path.push(format!("{}.elm", name));

    let file = File::create(path).unwrap();
    let ref mut w = BufWriter::new(file);
    w.write("Hello, World!".as_bytes()).unwrap();
}

extern crate syn;

use std::env;
use std::fs::File;
use std::io::{Write, BufWriter};
use syn::DeriveInput;

pub fn generate_elm(ast: &DeriveInput) {
    let mut path = env::current_dir().unwrap();
    let name = &ast.ident;
    path.push(format!("generated/{}.elm", name));

    let file = File::create(path).unwrap();
    let ref mut w = BufWriter::new(file);
    w.write("Hello, World!".as_bytes()).unwrap();
}

--- 
+++ 
@@ -1,14 +1,17 @@
 extern crate syn;
 
 use std::env;
-use std::fs::File;
+use std::fs::{File, create_dir};
 use std::io::{Write, BufWriter};
 use syn::DeriveInput;
 
 pub fn generate_elm(ast: &DeriveInput) {
     let mut path = env::current_dir().unwrap();
+    path.push("generated");
+    if path.exists() && path.is_file() { panic!("expecting \"generated\" to be a directory"); }
+    if !path.exists() { create_dir(path.clone()).expect("problem creating \"generated\" directory") }
     let name = &ast.ident;
-    path.push(format!("generated/{}.elm", name));
+    path.push(format!("{}.elm", name));
 
     let file = File::create(path).unwrap();
     let ref mut w = BufWriter::new(file);
Create generated directory unless it is already created
