Skip to content

Commit c185bcf

Browse files
committed
Use modules rather than include! for codegenned stuff
1 parent ed789cf commit c185bcf

File tree

6 files changed

+31
-4
lines changed

6 files changed

+31
-4
lines changed

codegen/src/sqlstate.rs

+9
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ pub fn build(path: &Path) {
1717

1818
let codes = parse_codes();
1919

20+
make_header(&mut file);
2021
make_enum(&codes, &mut file);
2122
make_map(&codes, &mut file);
2223
make_impl(&codes, &mut file);
@@ -69,6 +70,14 @@ fn variant_name(code: &str) -> Option<String> {
6970
}
7071
}
7172

73+
fn make_header(file: &mut BufWriter<File>) {
74+
write!(file,
75+
"// Autogenerated file - DO NOT EDIT
76+
use phf;
77+
"
78+
).unwrap();
79+
}
80+
7281
fn make_enum(codes: &[Code], file: &mut BufWriter<File>) {
7382
write!(file,
7483
r#"/// SQLSTATE error codes

codegen/src/types.rs

+11
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ pub fn build(path: &Path) {
2424
let ranges = parse_ranges();
2525
let types = parse_types(&ranges);
2626

27+
make_header(&mut file);
2728
make_enum(&mut file, &types);
2829
make_display_impl(&mut file);
2930
make_impl(&mut file, &types);
@@ -113,6 +114,16 @@ fn parse_types(ranges: &BTreeMap<u32, u32>) -> BTreeMap<u32, Type> {
113114
types
114115
}
115116

117+
fn make_header(w: &mut BufWriter<File>) {
118+
write!(w,
119+
"// Autogenerated file - DO NOT EDIT
120+
use std::fmt;
121+
122+
use types::{{Oid, Kind, Other}};
123+
"
124+
).unwrap();
125+
}
126+
116127
fn make_enum(w: &mut BufWriter<File>, types: &BTreeMap<u32, Type>) {
117128
write!(w,
118129
"/// A Postgres type.

src/error/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
//! Error types.
22
33
use byteorder;
4-
use phf;
54
use std::error;
65
use std::convert::From;
76
use std::fmt;
87
use std::io;
98
use std::result;
109
use std::collections::HashMap;
1110

11+
pub use self::sqlstate::SqlState;
1212
use {Result, DbErrorNew};
1313

14-
include!("sqlstate.rs");
14+
mod sqlstate;
1515

1616
/// A Postgres error or notice.
1717
#[derive(Clone, PartialEq, Eq)]

src/error/sqlstate.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// Autogenerated file - DO NOT EDIT
2+
use phf;
13
/// SQLSTATE error codes
24
#[derive(PartialEq, Eq, Clone, Debug)]
35
pub enum SqlState {

src/types/mod.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use std::sync::Arc;
88
use byteorder::{ReadBytesExt, WriteBytesExt, BigEndian};
99

1010
pub use self::slice::Slice;
11+
pub use self::types::Type;
1112
use {Result, SessionInfoNew, InnerConnection, OtherNew, WrongTypeNew, FieldNew};
1213
use error::Error;
1314
use util;
@@ -70,6 +71,8 @@ mod chrono;
7071
#[cfg(feature = "eui48")]
7172
mod eui48;
7273

74+
mod types;
75+
7376
/// A structure providing information for conversion methods.
7477
pub struct SessionInfo<'a> {
7578
conn: &'a InnerConnection,
@@ -149,8 +152,6 @@ impl FieldNew for Field {
149152
}
150153
}
151154

152-
include!("types.rs");
153-
154155
/// Information about an unknown type.
155156
#[derive(PartialEq, Eq, Clone)]
156157
pub struct Other(Arc<OtherInner>);

src/types/types.rs

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
// Autogenerated file - DO NOT EDIT
2+
use std::fmt;
3+
4+
use types::{Oid, Kind, Other};
15
/// A Postgres type.
26
#[derive(PartialEq, Eq, Clone, Debug)]
37
pub enum Type {

0 commit comments

Comments
 (0)