Skip to content

Commit d349715

Browse files
committed
Support CIDR as well
1 parent 00d0f9e commit d349715

3 files changed

Lines changed: 16 additions & 4 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ types. The driver currently supports the following conversions:
206206
</tr>
207207
<tr>
208208
<td>IpAddr</td>
209-
<td>INET</td>
209+
<td>INET/CIDR</td>
210210
</tr>
211211
<tr>
212212
<td>time::Timespec</td>

src/types/mod.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,7 @@ const INT4OID: Oid = 23;
324324
const TEXTOID: Oid = 25;
325325
const JSONOID: Oid = 114;
326326
const JSONARRAYOID: Oid = 199;
327+
const CIDROID: Oid = 650;
327328
const FLOAT4OID: Oid = 700;
328329
const FLOAT8OID: Oid = 701;
329330
const INETOID: Oid = 869;
@@ -429,6 +430,8 @@ make_postgres_type!(
429430
TEXTOID => Text,
430431
#[doc="JSON"]
431432
JSONOID => Json,
433+
#[doc="CIDR"]
434+
CIDROID => Cidr,
432435
#[doc="JSON[]"]
433436
JSONARRAYOID => JsonArray member Json,
434437
#[doc="FLOAT4/REAL"]
@@ -580,7 +583,7 @@ from_raw_from_impl!(Int8, i64)
580583
from_raw_from_impl!(Float4, f32)
581584
from_raw_from_impl!(Float8, f64)
582585
from_raw_from_impl!(Json, json::Json)
583-
from_raw_from_impl!(Inet, IpAddr)
586+
from_raw_from_impl!(Inet | Cidr, IpAddr)
584587

585588
from_raw_from_impl!(Int4Range, Range<i32>)
586589
from_raw_from_impl!(Int8Range, Range<i64>)
@@ -738,7 +741,7 @@ to_raw_to_impl!(Bool, bool)
738741
to_raw_to_impl!(ByteA, Vec<u8>)
739742
to_raw_to_impl!(Varchar | Text | CharN | Name, String)
740743
to_raw_to_impl!(Json, json::Json)
741-
to_raw_to_impl!(Inet, IpAddr)
744+
to_raw_to_impl!(Inet | Cidr, IpAddr)
742745
to_raw_to_impl!(Char, i8)
743746
to_raw_to_impl!(Int2, i16)
744747
to_raw_to_impl!(Int4, i32)

tests/types/mod.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,16 @@ fn test_inet_params() {
170170
test_type("INET", &[(Some(from_str::<IpAddr>("127.0.0.1").unwrap()),
171171
"'127.0.0.1'"),
172172
(Some(from_str("2001:0db8:85a3:0000:0000:8a2e:0370:7334").unwrap()),
173-
"'2001:0db8:85a3:0000:0000:8a2e:0370:7334'"),
173+
"'2001:0db8:85a3:0000:0000:8a2e:0370:7334'"),
174+
(None, "NULL")])
175+
}
176+
177+
#[test]
178+
fn test_cidr_params() {
179+
test_type("CIDR", &[(Some(from_str::<IpAddr>("127.0.0.1").unwrap()),
180+
"'127.0.0.1'"),
181+
(Some(from_str("2001:0db8:85a3:0000:0000:8a2e:0370:7334").unwrap()),
182+
"'2001:0db8:85a3:0000:0000:8a2e:0370:7334'"),
174183
(None, "NULL")])
175184
}
176185

0 commit comments

Comments
 (0)