From c185bcf43f125465cb70898e39ecfd318ee8f58c Mon Sep 17 00:00:00 2001 From: Steven Fackler Date: Sun, 21 Feb 2016 13:37:29 -0800 Subject: [PATCH] Use modules rather than include! for codegenned stuff --- codegen/src/sqlstate.rs | 9 +++++++++ codegen/src/types.rs | 11 +++++++++++ src/error/mod.rs | 4 ++-- src/error/sqlstate.rs | 2 ++ src/types/mod.rs | 5 +++-- src/types/types.rs | 4 ++++ 6 files changed, 31 insertions(+), 4 deletions(-) diff --git a/codegen/src/sqlstate.rs b/codegen/src/sqlstate.rs index 419778a4..401dc290 100644 --- a/codegen/src/sqlstate.rs +++ b/codegen/src/sqlstate.rs @@ -17,6 +17,7 @@ pub fn build(path: &Path) { let codes = parse_codes(); + make_header(&mut file); make_enum(&codes, &mut file); make_map(&codes, &mut file); make_impl(&codes, &mut file); @@ -69,6 +70,14 @@ fn variant_name(code: &str) -> Option { } } +fn make_header(file: &mut BufWriter) { + write!(file, +"// Autogenerated file - DO NOT EDIT +use phf; +" + ).unwrap(); +} + fn make_enum(codes: &[Code], file: &mut BufWriter) { write!(file, r#"/// SQLSTATE error codes diff --git a/codegen/src/types.rs b/codegen/src/types.rs index 658acc6e..c17e29d3 100644 --- a/codegen/src/types.rs +++ b/codegen/src/types.rs @@ -24,6 +24,7 @@ pub fn build(path: &Path) { let ranges = parse_ranges(); let types = parse_types(&ranges); + make_header(&mut file); make_enum(&mut file, &types); make_display_impl(&mut file); make_impl(&mut file, &types); @@ -113,6 +114,16 @@ fn parse_types(ranges: &BTreeMap) -> BTreeMap { types } +fn make_header(w: &mut BufWriter) { + write!(w, +"// Autogenerated file - DO NOT EDIT +use std::fmt; + +use types::{{Oid, Kind, Other}}; +" + ).unwrap(); +} + fn make_enum(w: &mut BufWriter, types: &BTreeMap) { write!(w, "/// A Postgres type. diff --git a/src/error/mod.rs b/src/error/mod.rs index d676c333..3074cfdd 100644 --- a/src/error/mod.rs +++ b/src/error/mod.rs @@ -1,7 +1,6 @@ //! Error types. use byteorder; -use phf; use std::error; use std::convert::From; use std::fmt; @@ -9,9 +8,10 @@ use std::io; use std::result; use std::collections::HashMap; +pub use self::sqlstate::SqlState; use {Result, DbErrorNew}; -include!("sqlstate.rs"); +mod sqlstate; /// A Postgres error or notice. #[derive(Clone, PartialEq, Eq)] diff --git a/src/error/sqlstate.rs b/src/error/sqlstate.rs index a3f38893..2c7483ff 100644 --- a/src/error/sqlstate.rs +++ b/src/error/sqlstate.rs @@ -1,3 +1,5 @@ +// Autogenerated file - DO NOT EDIT +use phf; /// SQLSTATE error codes #[derive(PartialEq, Eq, Clone, Debug)] pub enum SqlState { diff --git a/src/types/mod.rs b/src/types/mod.rs index dd6b9d83..ac34190a 100644 --- a/src/types/mod.rs +++ b/src/types/mod.rs @@ -8,6 +8,7 @@ use std::sync::Arc; use byteorder::{ReadBytesExt, WriteBytesExt, BigEndian}; pub use self::slice::Slice; +pub use self::types::Type; use {Result, SessionInfoNew, InnerConnection, OtherNew, WrongTypeNew, FieldNew}; use error::Error; use util; @@ -70,6 +71,8 @@ mod chrono; #[cfg(feature = "eui48")] mod eui48; +mod types; + /// A structure providing information for conversion methods. pub struct SessionInfo<'a> { conn: &'a InnerConnection, @@ -149,8 +152,6 @@ impl FieldNew for Field { } } -include!("types.rs"); - /// Information about an unknown type. #[derive(PartialEq, Eq, Clone)] pub struct Other(Arc); diff --git a/src/types/types.rs b/src/types/types.rs index 9ff82c44..31d11c83 100644 --- a/src/types/types.rs +++ b/src/types/types.rs @@ -1,3 +1,7 @@ +// Autogenerated file - DO NOT EDIT +use std::fmt; + +use types::{Oid, Kind, Other}; /// A Postgres type. #[derive(PartialEq, Eq, Clone, Debug)] pub enum Type {