Skip to content

Commit 0c86f93

Browse files
committed
Add multirange kind and run cargo fmt
1 parent f413e66 commit 0c86f93

File tree

4 files changed

+216
-564
lines changed

4 files changed

+216
-564
lines changed

Diff for: codegen/src/type_gen.rs

+21-3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ struct Type {
1717
variant: String,
1818
ident: String,
1919
kind: String,
20+
typtype: Option<String>,
2021
element: u32,
2122
doc: String,
2223
}
@@ -217,12 +218,18 @@ fn parse_types() -> BTreeMap<u32, Type> {
217218
continue;
218219
}
219220

221+
let typtype = raw_type.get("typtype").cloned();
222+
220223
let element = match &*kind {
221-
"R" => match &*raw_type["typtype"] {
224+
"R" => match typtype
225+
.as_ref()
226+
.expect("range type must have typtype")
227+
.as_str()
228+
{
222229
"r" => range_elements[&oid],
223230
"m" => multi_range_elements[&oid],
224231
typtype => panic!("invalid range typtype {}", typtype),
225-
}
232+
},
226233
"A" => oids_by_name[&raw_type["typelem"]],
227234
_ => 0,
228235
};
@@ -248,6 +255,7 @@ fn parse_types() -> BTreeMap<u32, Type> {
248255
variant,
249256
ident,
250257
kind: "A".to_string(),
258+
typtype: None,
251259
element: oid,
252260
doc,
253261
};
@@ -259,6 +267,7 @@ fn parse_types() -> BTreeMap<u32, Type> {
259267
variant,
260268
ident,
261269
kind,
270+
typtype,
262271
element,
263272
doc,
264273
};
@@ -362,7 +371,16 @@ fn make_impl(w: &mut BufWriter<File>, types: &BTreeMap<u32, Type>) {
362371
let kind = match &*type_.kind {
363372
"P" => "Pseudo".to_owned(),
364373
"A" => format!("Array(Type(Inner::{}))", types[&type_.element].variant),
365-
"R" => format!("Range(Type(Inner::{}))", types[&type_.element].variant),
374+
"R" => match type_
375+
.typtype
376+
.as_ref()
377+
.expect("range type must have typtype")
378+
.as_str()
379+
{
380+
"r" => format!("Range(Type(Inner::{}))", types[&type_.element].variant),
381+
"m" => format!("Multirange(Type(Inner::{}))", types[&type_.element].variant),
382+
typtype => panic!("invalid range typtype {}", typtype),
383+
},
366384
_ => "Simple".to_owned(),
367385
};
368386

Diff for: postgres-types/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,8 @@ pub enum Kind {
320320
Array(Type),
321321
/// A range type along with the type of its elements.
322322
Range(Type),
323+
/// A multirange type along with the type of its elements.
324+
Multirange(Type),
323325
/// A domain type along with its underlying type.
324326
Domain(Type),
325327
/// A composite type along with information about its fields.

0 commit comments

Comments
 (0)