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

Add support for cidr 0.3 under separate feature#1183

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
sfackler merged 1 commit intorust-postgres:masterfromrs-sac:upstream
Feb 2, 2025
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletionspostgres-types/Cargo.toml
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -16,6 +16,7 @@ array-impls = ["array-init"]
js = ["postgres-protocol/js"]
with-bit-vec-0_6 = ["bit-vec-06"]
with-cidr-0_2 = ["cidr-02"]
with-cidr-0_3 = ["cidr-03"]
with-chrono-0_4 = ["chrono-04"]
with-eui48-0_4 = ["eui48-04"]
with-eui48-1 = ["eui48-1"]
Expand All@@ -41,6 +42,7 @@ chrono-04 = { version = "0.4.16", package = "chrono", default-features = false,
"clock",
], optional = true }
cidr-02 = { version = "0.2", package = "cidr", optional = true }
cidr-03 = { version = "0.3", package = "cidr", optional = true }
# eui48-04 will stop compiling and support will be removed
# See https://github.com/sfackler/rust-postgres/issues/1073
eui48-04 = { version = "0.4", package = "eui48", optional = true }
Expand Down
44 changes: 44 additions & 0 deletionspostgres-types/src/cidr_03.rs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
use bytes::BytesMut;
use cidr_03::{IpCidr, IpInet};
use postgres_protocol::types;
use std::error::Error;

use crate::{FromSql, IsNull, ToSql, Type};

impl<'a> FromSql<'a> for IpCidr {
fn from_sql(_: &Type, raw: &[u8]) -> Result<Self, Box<dyn Error + Sync + Send>> {
let inet = types::inet_from_sql(raw)?;
Ok(IpCidr::new(inet.addr(), inet.netmask())?)
}

accepts!(CIDR);
}

impl ToSql for IpCidr {
fn to_sql(&self, _: &Type, w: &mut BytesMut) -> Result<IsNull, Box<dyn Error + Sync + Send>> {
types::inet_to_sql(self.first_address(), self.network_length(), w);
Ok(IsNull::No)
}

accepts!(CIDR);
to_sql_checked!();
}

impl<'a> FromSql<'a> for IpInet {
fn from_sql(_: &Type, raw: &[u8]) -> Result<Self, Box<dyn Error + Sync + Send>> {
let inet = types::inet_from_sql(raw)?;
Ok(IpInet::new(inet.addr(), inet.netmask())?)
}

accepts!(INET);
}

impl ToSql for IpInet {
fn to_sql(&self, _: &Type, w: &mut BytesMut) -> Result<IsNull, Box<dyn Error + Sync + Send>> {
types::inet_to_sql(self.address(), self.network_length(), w);
Ok(IsNull::No)
}

accepts!(INET);
to_sql_checked!();
}
2 changes: 2 additions & 0 deletionspostgres-types/src/lib.rs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -268,6 +268,8 @@ mod bit_vec_06;
mod chrono_04;
#[cfg(feature = "with-cidr-0_2")]
mod cidr_02;
#[cfg(feature = "with-cidr-0_3")]
mod cidr_03;
#[cfg(feature = "with-eui48-0_4")]
mod eui48_04;
#[cfg(feature = "with-eui48-1")]
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp