Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit0785381

Browse files
authored
Merge pull request#1183 from rs-sac/upstream
Add support for cidr 0.3 under separate feature
2 parents263fb90 +eea7f13 commit0785381

File tree

3 files changed

+48
-0
lines changed

3 files changed

+48
-0
lines changed

‎postgres-types/Cargo.toml‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ array-impls = ["array-init"]
1616
js = ["postgres-protocol/js"]
1717
with-bit-vec-0_6 = ["bit-vec-06"]
1818
with-cidr-0_2 = ["cidr-02"]
19+
with-cidr-0_3 = ["cidr-03"]
1920
with-chrono-0_4 = ["chrono-04"]
2021
with-eui48-0_4 = ["eui48-04"]
2122
with-eui48-1 = ["eui48-1"]
@@ -41,6 +42,7 @@ chrono-04 = { version = "0.4.16", package = "chrono", default-features = false,
4142
"clock",
4243
],optional =true }
4344
cidr-02 = {version ="0.2",package ="cidr",optional =true }
45+
cidr-03 = {version ="0.3",package ="cidr",optional =true }
4446
# eui48-04 will stop compiling and support will be removed
4547
# See https://github.com/sfackler/rust-postgres/issues/1073
4648
eui48-04 = {version ="0.4",package ="eui48",optional =true }

‎postgres-types/src/cidr_03.rs‎

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
use bytes::BytesMut;
2+
use cidr_03::{IpCidr,IpInet};
3+
use postgres_protocol::types;
4+
use std::error::Error;
5+
6+
usecrate::{FromSql,IsNull,ToSql,Type};
7+
8+
impl<'a>FromSql<'a>forIpCidr{
9+
fnfrom_sql(_:&Type,raw:&[u8]) ->Result<Self,Box<dynError +Sync +Send>>{
10+
let inet = types::inet_from_sql(raw)?;
11+
Ok(IpCidr::new(inet.addr(), inet.netmask())?)
12+
}
13+
14+
accepts!(CIDR);
15+
}
16+
17+
implToSqlforIpCidr{
18+
fnto_sql(&self, _:&Type,w:&mutBytesMut) ->Result<IsNull,Box<dynError +Sync +Send>>{
19+
types::inet_to_sql(self.first_address(),self.network_length(), w);
20+
Ok(IsNull::No)
21+
}
22+
23+
accepts!(CIDR);
24+
to_sql_checked!();
25+
}
26+
27+
impl<'a>FromSql<'a>forIpInet{
28+
fnfrom_sql(_:&Type,raw:&[u8]) ->Result<Self,Box<dynError +Sync +Send>>{
29+
let inet = types::inet_from_sql(raw)?;
30+
Ok(IpInet::new(inet.addr(), inet.netmask())?)
31+
}
32+
33+
accepts!(INET);
34+
}
35+
36+
implToSqlforIpInet{
37+
fnto_sql(&self, _:&Type,w:&mutBytesMut) ->Result<IsNull,Box<dynError +Sync +Send>>{
38+
types::inet_to_sql(self.address(),self.network_length(), w);
39+
Ok(IsNull::No)
40+
}
41+
42+
accepts!(INET);
43+
to_sql_checked!();
44+
}

‎postgres-types/src/lib.rs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,8 @@ mod bit_vec_06;
268268
mod chrono_04;
269269
#[cfg(feature ="with-cidr-0_2")]
270270
mod cidr_02;
271+
#[cfg(feature ="with-cidr-0_3")]
272+
mod cidr_03;
271273
#[cfg(feature ="with-eui48-0_4")]
272274
mod eui48_04;
273275
#[cfg(feature ="with-eui48-1")]

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp