Use 'write!(out.front, ...)' to write to the front matter
diff --git a/gen/src/out.rs b/gen/src/out.rs
index f07a0d3..c21ad78 100644
--- a/gen/src/out.rs
+++ b/gen/src/out.rs
@@ -7,10 +7,11 @@
     pub namespace: Namespace,
     pub header: bool,
     pub include: Includes,
+    pub front: Content,
     content: RefCell<Content>,
 }
 
-struct Content {
+pub struct Content {
     bytes: Vec<u8>,
     section_pending: bool,
     blocks_pending: Vec<&'static str>,
@@ -22,11 +23,8 @@
             namespace,
             header,
             include: Includes::new(),
-            content: RefCell::new(Content {
-                bytes: Vec::new(),
-                section_pending: false,
-                blocks_pending: Vec::new(),
-            }),
+            front: Content::new(),
+            content: RefCell::new(Content::new()),
         }
     }
 
@@ -56,12 +54,17 @@
         Write::write_fmt(content, args).unwrap();
     }
 
-    pub fn extend(&self, other: &Self) {
-        self.content.borrow_mut().write_bytes(&other.content.borrow().bytes);
-    }
-
     pub fn content(&self) -> Vec<u8> {
-        self.content.borrow().bytes.clone()
+        let front = &self.front.bytes;
+        let content = &self.content.borrow().bytes;
+        let len = front.len() + !front.is_empty() as usize + content.len();
+        let mut out = Vec::with_capacity(len);
+        out.extend_from_slice(front);
+        if !front.is_empty() {
+            out.push(b'\n');
+        }
+        out.extend_from_slice(content);
+        out
     }
 }
 
@@ -73,6 +76,18 @@
 }
 
 impl Content {
+    pub fn write_fmt(&mut self, args: Arguments) {
+        Write::write_fmt(self, args).unwrap();
+    }
+
+    fn new() -> Self {
+        Content {
+            bytes: Vec::new(),
+            section_pending: false,
+            blocks_pending: Vec::new(),
+        }
+    }
+
     fn write_bytes(&mut self, b: &[u8]) {
         if !b.is_empty() {
             if !self.blocks_pending.is_empty() {
diff --git a/gen/src/write.rs b/gen/src/write.rs
index 88a0734..ae90047 100644
--- a/gen/src/write.rs
+++ b/gen/src/write.rs
@@ -17,6 +17,10 @@
     let mut out_file = OutFile::new(namespace.clone(), header);
     let out = &mut out_file;
 
+    if header {
+        writeln!(out.front, "#pragma once");
+    }
+
     out.include.extend(opt.include);
     for api in apis {
         if let Api::Include(include) = api {
@@ -110,17 +114,9 @@
         write_generic_instantiations(out, types);
     }
 
-    // We collected necessary includes lazily while generating the above. Now
-    // put it all together.
-    let mut full_file = OutFile::new(namespace.clone(), header);
-    let full = &mut full_file;
-    if header {
-        writeln!(full, "#pragma once");
-    }
-    write!(full, "{}", out.include);
-    full.next_section();
-    full.extend(out);
-    full_file
+    write!(out.front, "{}", out.include);
+
+    out_file
 }
 
 fn write_includes(out: &mut OutFile, types: &Types) {