Merge pull request #405 from dtolnay/sort

Emit data structures and functions in source order
diff --git a/gen/src/write.rs b/gen/src/write.rs
index 0369ef5..7753ebf 100644
--- a/gen/src/write.rs
+++ b/gen/src/write.rs
@@ -20,7 +20,8 @@
 
     let apis_by_namespace = NamespaceEntries::new(apis);
     write_namespace_forward_declarations(out, &apis_by_namespace);
-    write_namespace_contents(out, &apis_by_namespace);
+    write_data_structures(out, apis);
+    write_functions(out, apis);
 
     if !header {
         out.next_section();
@@ -53,9 +54,7 @@
     }
 }
 
-fn write_namespace_contents<'a>(out: &mut OutFile<'a>, ns_entries: &'a NamespaceEntries<'a>) {
-    let apis = ns_entries.direct_content();
-
+fn write_data_structures<'a>(out: &mut OutFile<'a>, apis: &'a [Api]) {
     let mut methods_for_type = HashMap::new();
     for api in apis {
         if let Api::RustFunction(efn) = api {
@@ -102,7 +101,9 @@
             }
         }
     }
+}
 
+fn write_functions<'a>(out: &mut OutFile<'a>, apis: &'a [Api]) {
     if !out.header {
         for api in apis {
             match api {
@@ -119,10 +120,6 @@
             write_rust_function_shim(out, efn);
         }
     }
-
-    for (_, nested_ns_entries) in ns_entries.nested_content() {
-        write_namespace_contents(out, nested_ns_entries);
-    }
 }
 
 fn pick_includes_and_builtins(out: &mut OutFile) {